001/*
002 * JDrupes Builder
003 * Copyright (C) 2026 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.eclipse;
020
021import java.util.Objects;
022import org.jdrupes.builder.api.Intent;
023import org.jdrupes.builder.core.DefaultResourceRequest;
024
025/// An implementation of [EclipseLauncherRequest].
026///
027public class DefaultEclipseLauncherRequest
028        extends DefaultResourceRequest<EclipseLauncher>
029        implements EclipseLauncherRequest {
030
031    private String mainClass;
032    private String arguments;
033    private String vmArguments;
034
035    /// Initializes a new default eclipse resource request.
036    ///
037    protected DefaultEclipseLauncherRequest() {
038        super(EclipseTypes.EclipseLauncherType);
039    }
040
041    /// Creates a new request for a configuration with the given name.
042    /// The request is created with intent [Intent#Supply] because this
043    /// is the common usage.
044    ///
045    /// @param name the name
046    /// @return the default eclipse launcher request
047    ///
048    public static DefaultEclipseLauncherRequest create(String name) {
049        return (DefaultEclipseLauncherRequest) new DefaultEclipseLauncherRequest()
050            .withName(name).using(Intent.Supply);
051    }
052
053    @Override
054    public DefaultEclipseLauncherRequest clone() {
055        // No special handling of attributes required
056        return (DefaultEclipseLauncherRequest) super.clone();
057    }
058
059    /// Set the main class for the launch configuration.
060    ///
061    /// @param mainClass the fully qualified main class name
062    /// @return the launcher for method chaining
063    ///
064    public DefaultEclipseLauncherRequest withMainClass(String mainClass) {
065        var result = clone();
066        result.mainClass = mainClass;
067        return result;
068    }
069
070    /// The arguments to use in the launch configuration.
071    ///
072    /// @param arguments the program arguments
073    /// @return the launcher for method chaining
074    ///
075    public DefaultEclipseLauncherRequest withArguments(String arguments) {
076        var result = clone();
077        result.arguments = arguments;
078        return result;
079    }
080
081    /// The VM arguments to use in the launch configuration.
082    ///
083    /// @param vmArguments the VM arguments
084    /// @return the launcher for method chaining
085    ///
086    public DefaultEclipseLauncherRequest withVmArguments(String vmArguments) {
087        var result = clone();
088        result.vmArguments = vmArguments;
089        return result;
090    }
091
092    @Override
093    public String mainClass() {
094        return mainClass;
095    }
096
097    @Override
098    public String arguments() {
099        return arguments;
100    }
101
102    @Override
103    public String vmArguments() {
104        return vmArguments;
105    }
106
107    @Override
108    public int hashCode() {
109        final int prime = 31;
110        int result = super.hashCode();
111        result
112            = prime * result + Objects.hash(arguments, mainClass, vmArguments);
113        return result;
114    }
115
116    @Override
117    public boolean equals(Object obj) {
118        if (this == obj) {
119            return true;
120        }
121        if (!super.equals(obj)) {
122            return false;
123        }
124        if (!(obj instanceof DefaultEclipseLauncherRequest)) {
125            return false;
126        }
127        DefaultEclipseLauncherRequest other
128            = (DefaultEclipseLauncherRequest) obj;
129        return Objects.equals(arguments, other.arguments)
130            && Objects.equals(mainClass, other.mainClass)
131            && Objects.equals(vmArguments, other.vmArguments);
132    }
133
134}