Skip to content

Commit

Permalink
Rename WindupConfigurationPackageModel to PackageModel. TODO: Should …
Browse files Browse the repository at this point in the history
…be in the Java addon.

Add javadoc to WindupConfigurationModel.
  • Loading branch information
OndraZizka committed Jul 22, 2014
1 parent 613d51e commit 8eed922
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 24 deletions.
@@ -0,0 +1,80 @@
package org.jboss.windup.exec.config;

import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* Holds global configuration and plugin-specific configuration.
*
* @author Ondrej Zizka
*/
@XmlRootElement(name="config")
@XmlAccessorType( XmlAccessType.NONE )
public class Configuration {

@XmlElement
private CoreConfiguration globalConfig = new CoreConfiguration();

private List<RulesetSpecificProperty> rulesetConfigs = new LinkedList();



/**
* What to do if some resource already exists.
* MERGE (ModelNode into current model) and ASK (interactive) are not supported yet.
*/
public enum IfExists {
FAIL, WARN, SKIP, MERGE, OVERWRITE, ASK, GUI;

/** The same as valueOf(), only case-insensitive. */
public static IfExists valueOf_Custom(String str) throws IllegalArgumentException {
try {
return valueOf( str.toUpperCase() );
}
catch( IllegalArgumentException | NullPointerException ex ){
throw new IllegalArgumentException("ifExists must be one of FAIL, WARN, SKIP, MERGE, OVERWRITE, ASK. Was: " + str);
}
}

public static final String PARAM_NAME = "ifExists";
}// enum




/**
* Triplet for module specific property, e.g --conf.logging.merge=true .
*/
public static class RulesetSpecificProperty{

private String moduleId;
private String propName;
private String value;

public RulesetSpecificProperty(String moduleId, String propName, String value) {
this.moduleId = moduleId;
this.propName = propName;
this.value = value;
}

public String getModuleId() { return moduleId; }
public void setModuleId(String moduleId) { this.moduleId = moduleId; }
public String getPropName() { return propName; }
public void setPropName(String propName) { this.propName = propName; }
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }
}


//<editor-fold defaultstate="collapsed" desc="get/set">
public CoreConfiguration getGlobal() { return globalConfig; }
public void setGlobalConfig(CoreConfiguration options) { this.globalConfig = options; }
public List<RulesetSpecificProperty> getModuleConfigs() { return rulesetConfigs; }
public void setModuleConfigs(List<RulesetSpecificProperty> moduleConfigs) { this.rulesetConfigs = moduleConfigs; }
//</editor-fold>

}// class
@@ -0,0 +1,76 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 .
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package org.jboss.windup.exec.config;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;


/**
* Class for storing global information needed for migration. Like dir of AS7, AS5, and profiles
* <p/>
* With regard of possibility to migrate from other vendors' AS,
* split to AS 7 config class, and then have 1 class per server (AS 5, WebLogic, ...).
*/
@XmlRootElement(name="global")
public class CoreConfiguration {

private Set<String> appPaths = new HashSet();

private boolean skipValidation = false;

private boolean dryRun = false;

private boolean isTestRun = false;

// This is rather for test purposes. If null, all are used.
private List<String> onlyRulesets = new LinkedList();

private String reportDir = "MigrationReport";

private String externalMigratorsDir;

// User vars - accessible in EL's and Groovy scripts. WINDUP-132
private Map<String, String> userVars = new HashMap();



//<editor-fold defaultstate="collapsed" desc="get/set">
public Set<String> getDeploymentsPaths() { return appPaths; }
public void addDeploymentPath(String deplPath) { this.appPaths.add( deplPath ); }

public boolean isSkipValidation() { return skipValidation; }
public void setSkipValidation(boolean skipValidation) { this.skipValidation = skipValidation; }

public boolean isDryRun() { return dryRun; }
public void setDryRun( boolean dryRun ) { this.dryRun = dryRun; }

public boolean isTestRun() { return isTestRun; }
public void setTestRun( boolean isTestRun ) { this.isTestRun = isTestRun; }

public String getReportDir() { return reportDir; }
public void setReportDir( String reportDir ) { this.reportDir = reportDir; }

public String getExternalMigratorsDir() { return externalMigratorsDir; }
public void setExternalMigratorsDir( String externalMigratorsDir ) { this.externalMigratorsDir = externalMigratorsDir; }

public List<String> getOnlyMigrators() { return onlyRulesets; }
public List<String> addOnlyMigrator( String name ) { onlyRulesets.add(name); return onlyRulesets; }

// WINDUP-132
public Map<String, String> getUserVars() { return userVars; }
public String getUserVar( String name) { return userVars.get(name); }
public void setUserVar( String name, String val ) { this.userVars.put( name, val ); }
//</editor-fold>

}// class
Expand Up @@ -4,7 +4,7 @@
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

@TypeValue("WindupServiceConfigurationPackageModel")
public interface WindupConfigurationPackageModel extends WindupVertexFrame
public interface PackageModel extends WindupVertexFrame
{
@Property("packageName")
public String getPackageName();
Expand Down
Expand Up @@ -12,14 +12,17 @@
import com.tinkerpop.frames.modules.javahandler.JavaHandlerContext;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

@TypeValue("WindupServiceConfiguration")
@TypeValue("WindupConfiguration")
public interface WindupConfigurationModel extends WindupVertexFrame
{
public static final String PROPERTY_SOURCE_MODE = "sourceMode";
public static final String PROPERTY_FETCH_REMOTE_RESOURCES = "fetchRemoteResources";
public static final String PROPERTY_EXCLUDE_JAVA_PACKAGES = "excludeJavaPackages";
public static final String PROPERTY_SCAN_JAVA_PACKAGES = "scanJavaPackages";

/**
* The application to scan.
*/
@JavaHandler
void setInputPath(String inputPath);

Expand All @@ -29,6 +32,9 @@ public interface WindupConfigurationModel extends WindupVertexFrame
@Adjacency(label = "inputPath", direction = Direction.OUT)
void setInputPath(FileModel inputPath);

/**
* Where to put the report.
*/
@JavaHandler
void setOutputPath(String outputPath);

Expand All @@ -38,82 +44,114 @@ public interface WindupConfigurationModel extends WindupVertexFrame
@Adjacency(label = "outputPath", direction = Direction.OUT)
void setOutputPath(FileModel outputPath);


/**
* This is for scanJavaPackageList, see Impl.
*/
@Adjacency(label = PROPERTY_SCAN_JAVA_PACKAGES, direction = Direction.OUT)
Iterable<WindupConfigurationPackageModel> getScanJavaPackages();
Iterable<PackageModel> getScanJavaPackages();

@Adjacency(label = PROPERTY_SCAN_JAVA_PACKAGES, direction = Direction.OUT)
void addScanJavaPackages(WindupConfigurationPackageModel scanJavaPackage);
void addScanJavaPackages(PackageModel scanJavaPackage);

@Adjacency(label = PROPERTY_SCAN_JAVA_PACKAGES, direction = Direction.OUT)
void setScanJavaPackages(Iterable<WindupConfigurationPackageModel> scanJavaPackage);
void setScanJavaPackages(Iterable<PackageModel> scanJavaPackage);


/**
* What Java packages to exclude during scanning of archives (blacklist).
*/
@Adjacency(label = PROPERTY_EXCLUDE_JAVA_PACKAGES, direction = Direction.OUT)
Iterable<WindupConfigurationPackageModel> getExcludeJavaPackages();
Iterable<PackageModel> getExcludeJavaPackages();

@Adjacency(label = PROPERTY_EXCLUDE_JAVA_PACKAGES, direction = Direction.OUT)
void addExcludeJavaPackage(WindupConfigurationPackageModel scanJavaPackage);
void addExcludeJavaPackage(PackageModel scanJavaPackage);

@Adjacency(label = PROPERTY_EXCLUDE_JAVA_PACKAGES, direction = Direction.OUT)
void setExcludeJavaPackages(Iterable<WindupConfigurationPackageModel> scanJavaPackage);
void setExcludeJavaPackages(Iterable<PackageModel> scanJavaPackage);

/**
* ??? I guess a whitelist?
*/
@JavaHandler
void setScanJavaPackageList(Iterable<String> pkgs);

@JavaHandler
void setExcludeJavaPackageList(Iterable<String> pkgs);


/**
* Not used.
*/
@Property(PROPERTY_FETCH_REMOTE_RESOURCES)
boolean isFetchRemoteResources();

@Property(PROPERTY_FETCH_REMOTE_RESOURCES)
void setFetchRemoteResources(boolean fetchRemoteResources);



@Property(PROPERTY_SOURCE_MODE)
boolean isSourceMode();

@Property(PROPERTY_SOURCE_MODE)
void setSourceMode(boolean sourceMode);


// Implementation to be used by Frames.
abstract class Impl implements WindupConfigurationModel, JavaHandlerContext<Vertex>
{
/**
* Converts the String into a FileModel.
*/
public void setInputPath(String inputPath)
{
FileModel fileModel = this.g().addVertex(null, FileModel.class);
fileModel.setFilePath(inputPath);
setInputPath(fileModel);
}

/**
* Converts the String into a FileModel.
*/
public void setOutputPath(String outputPath)
{
FileModel fileModel = this.g().addVertex(null, FileModel.class);
fileModel.setFilePath(outputPath);
setOutputPath(fileModel);
}


/**
* Converts the String's into a PackageModel's.
*/
public void setScanJavaPackageList(Iterable<String> pkgs)
{
setScanJavaPackages(new ArrayList<WindupConfigurationPackageModel>());
setScanJavaPackages(new ArrayList<PackageModel>());
if (pkgs != null)
{
for (String pkg : pkgs)
{
WindupConfigurationPackageModel m = g().addVertex(null,
WindupConfigurationPackageModel.class);
PackageModel m = g().addVertex(null,
PackageModel.class);
m.setPackageName(pkg);
addScanJavaPackages(m);
}
}
}

/**
* Converts the String's into a PackageModel's.
*/
public void setExcludeJavaPackageList(Iterable<String> pkgs)
{
setExcludeJavaPackages(new ArrayList<WindupConfigurationPackageModel>());
setExcludeJavaPackages(new ArrayList<PackageModel>());
if (pkgs != null)
{
for (String pkg : pkgs)
{
WindupConfigurationPackageModel m = g().addVertex(null,
WindupConfigurationPackageModel.class);
PackageModel m = g().addVertex(null,
PackageModel.class);
m.setPackageName(pkg);
addExcludeJavaPackage(m);
}
Expand Down
Expand Up @@ -44,16 +44,9 @@ public void perform(GraphRewrite event, EvaluationContext context, WindupConfigu
ProjectModel projectModel = payload.getInputPath().getProjectModel();
if (projectModel == null)
{
if (payload.isSourceMode())
{
throw new WindupException("Error, no project found in source-based input directory: "
+ payload.getInputPath().getFilePath());
}
else
{
throw new WindupException("Error, no project found in archive: "
+ payload.getInputPath().getFilePath());
}
String msg = payload.isSourceMode() ? "source-based input directory" : "archive";
throw new WindupException("Error, no project found in "+ msg + ": "
+ payload.getInputPath().getFilePath());
}
createApplicationReport(event.getGraphContext(), projectModel);
}
Expand Down

0 comments on commit 8eed922

Please sign in to comment.