List of usage examples for org.apache.maven.plugin MojoExecutionException MojoExecutionException
public MojoExecutionException(String message)
MojoExecutionException
exception providing a message
. From source file:com.change_vision.astah.DebugMojo.java
License:Apache License
public void execute() throws MojoExecutionException { AstahEdition edition;/*from w w w. ja v a2 s .c o m*/ try { edition = AstahEdition.valueOf(this.edition); } catch (IllegalArgumentException e) { String message = String.format("%s is not supported.", this.edition); throw new MojoExecutionException(message); } File targetPlugin = getTarget(); PluginPathsBuilder pathBuilder = new PluginPathsBuilder(targetPlugin); Set<String> jvmProp = new LinkedHashSet<String>(); jvmProp.add("-Xdebug"); jvmProp.add("-Xnoagent"); jvmProp.add("-Djava.compiler=NONE"); jvmProp.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + port); jvmProp.add(pathBuilder.build()); if (argLine != null && argLine.isEmpty() == false) { jvmProp.add(argLine); } LaunchAstah launch = new LaunchAstah(installDirectory, edition, jvmProp, getLog()); launch.execute(); }
From source file:com.change_vision.astah.LaunchMojo.java
License:Apache License
public void execute() throws MojoExecutionException { AstahEdition edition;/*from www . j a va 2 s. c o m*/ try { edition = AstahEdition.valueOf(this.edition); } catch (IllegalArgumentException e) { String message = String.format("%s is not supported.", this.edition); throw new MojoExecutionException(message); } File targetPlugin = getTarget(); PluginPathsBuilder pathBuilder = new PluginPathsBuilder(targetPlugin); Set<String> jvmProp = new HashSet<String>(); jvmProp.add(pathBuilder.build()); if (argLine != null && argLine.isEmpty() == false) { jvmProp.add(argLine); } LaunchAstah launch = new LaunchAstah(installDirectory, edition, jvmProp, getLog()); launch.execute(); }
From source file:com.chaschev.install.ExecMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { Preconditions.checkNotNull(className, "you need to set class name with -Dclass=your.ClassName"); try {//from ww w .j a v a 2 s . c om initialize(); Artifact artifact = new DefaultArtifact(artifactName); DependencyResult dependencyResult = resolveArtifact(artifact); List<ArtifactResult> artifacts = dependencyResult.getArtifactResults(); // List<ArtifactResult> artifactResults = getDependencies(artifact); new ExecObject(getLog(), artifact, artifacts, className, parseArgs(), systemProperties).execute(); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { getLog().error(e.toString(), e); throw new MojoExecutionException(e.toString()); } } }
From source file:com.chaschev.install.InstallMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { try {//from w ww . j av a2 s . c o m // FindAvailableVersions.main(null); initialize(); Artifact artifact = new DefaultArtifact(artifactName); DependencyResult dependencyResult = resolveArtifact(artifact); artifact = dependencyResult.getRoot().getArtifact(); List<ArtifactResult> dependencies = dependencyResult.getArtifactResults(); if (className != null) { new ExecObject(getLog(), artifact, dependencies, className, parseArgs(), systemProperties) .execute(); } Class<?> installation = new URLClassLoader(new URL[] { artifact.getFile().toURI().toURL() }) .loadClass("Installation"); List<Object[]> entries = (List<Object[]>) OpenBean2.getStaticFieldValue(installation, "shortcuts"); if (installTo == null) { installTo = findPath(); } File installToDir = new File(installTo); File classPathFile = writeClasspath(artifact, dependencies, installToDir); for (Object[] entry : entries) { String shortCut = (String) entry[0]; String className = entry[1] instanceof String ? entry[1].toString() : ((Class) entry[1]).getName(); File file; if (SystemUtils.IS_OS_WINDOWS) { file = new File(installToDir, shortCut + ".bat"); FileUtils.writeStringToFile(file, createLaunchScript(className, classPathFile)); } else { file = new File(installToDir, shortCut); FileUtils.writeStringToFile(file, createLaunchScript(className, classPathFile)); try { file.setExecutable(true, false); } catch (Exception e) { getLog().warn( "could not make '" + file.getAbsolutePath() + "' executable: " + e.toString()); } } getLog().info("created a shortcut: " + file.getAbsolutePath() + " -> " + className); } } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { getLog().error(e.toString(), e); throw new MojoExecutionException(e.toString()); } } }
From source file:com.chiralbehaviors.CoRE.generators.WorkspaceGenerator.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { List<String> types = getTypes(); List<String> variables = getVariables(types); List<String> columns = getColumns(variables); STGroup group = new STGroupFile("templates/workspace.stg"); ST workspace = group.getInstanceOf("generate"); workspace.add("imports", getImports()); workspace.add("types", types); workspace.add("variables", variables); workspace.add("columns", columns); File sourceFile = new File(outputDirectory, SOURCE_FILE); try {/*from w w w .ja v a2 s. co m*/ Files.deleteIfExists(sourceFile.toPath()); } catch (FileNotFoundException e) { throw new MojoExecutionException( String.format("Cannot find file for create %s", sourceFile.getAbsolutePath(), e)); } catch (IOException e) { throw new MojoExecutionException(String.format("Error creating file %s\nCause: %s", sourceFile.getAbsolutePath(), e.getMessage())); } sourceFile.getParentFile().mkdirs(); try (OutputStream os = new FileOutputStream(Files.createFile(sourceFile.toPath()).toFile())) { os.write(workspace.render().getBytes()); } catch (IOException e) { throw new MojoExecutionException( String.format("Error writing file %s", sourceFile.getAbsolutePath(), e)); } group = new STGroupFile("templates/ddl.stg"); ST cs = group.getInstanceOf("generate"); cs.add("columns", columns); sourceFile = new File(outputDirectory, CHANGESET_FILE); try { Files.deleteIfExists(sourceFile.toPath()); } catch (FileNotFoundException e) { throw new MojoExecutionException( String.format("Cannot find file for create %s", sourceFile.getAbsolutePath(), e)); } catch (IOException e) { throw new MojoExecutionException(String.format("Error creating file %s\nCause: %s", sourceFile.getAbsolutePath(), e.getMessage())); } sourceFile.getParentFile().mkdirs(); try (OutputStream os = new FileOutputStream(Files.createFile(sourceFile.toPath()).toFile())) { os.write(cs.render().getBytes()); } catch (IOException e) { throw new MojoExecutionException( String.format("Error writing file %s", sourceFile.getAbsolutePath(), e)); } }
From source file:com.choncms.maven.CopyPluginsMojo.java
License:Apache License
public void execute() throws MojoExecutionException { File plugins_dir = new File(outputDirectory, PLUGINS_DIR); if (!plugins_dir.exists()) { plugins_dir.mkdirs();/*from w ww . jav a 2 s . c o m*/ } getLog().info(" *** Building product. Copying plugins to: " + plugins_dir.getAbsolutePath()); File dropins_dir = new File(outputDirectory, DROPINS_DIR); if (!dropins_dir.exists()) { dropins_dir.mkdirs(); } TargetPlatform tp = TychoProjectUtils.getTargetPlatform(project); //LinkedList<TargetPlatform> pList = getPlatformsForSessionProjects(); ProductConfiguration product = loadProduct(DefaultReactorProject.adapt(project)); for (PluginRef ref : product.getPlugins()) { ArtifactDescriptor artifact = tp.getArtifact(org.eclipse.tycho.ArtifactKey.TYPE_ECLIPSE_PLUGIN, ref.getId(), ref.getVersion()); // getArtifact(pList, // org.eclipse.tycho.ArtifactKey.TYPE_ECLIPSE_PLUGIN, // ref.getId(), ref.getVersion()); if (artifact == null) { throw new MojoExecutionException(" MISSING ARTIFACT: " + ref.getId()); } else { File location = getArtifactLocation(artifact); copyArtifact(location, plugins_dir); } } if (targetDir != null) { targetDir.mkdirs(); try { FileUtils.copyDirectoryStructure(outputDirectory, targetDir); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java
License:Apache License
public void execute() throws MojoExecutionException { getLog().info("Bucket Name: " + bucketName); //getLog().info("Cloud Formation Stack Name: " + stackName); if (artifactFile == null || !artifactFile.isFile()) { throw new MojoExecutionException("Cannot find artifact file to upload"); }// ww w . java 2 s. c om String artifactKey = artifactFile.getName(); getLog().info("Artifact Name: " + artifactKey); BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonCloudFormationClient cfClient = new AmazonCloudFormationClient(awsCredentials); cfClient.setEndpoint(getCloudFormationEndPoint()); AmazonS3Client s3Client = new AmazonS3Client(awsCredentials); // Upload Artifact to S3 try { getLog().info("Uploading artifact to S3..."); s3Client.putObject(bucketName, artifactKey, artifactFile); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Upload File to S3", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Upload File to S3", e); } // Update each stack with the new artifact file for (String stackName : stackNames) { getLog().info("Cloud Formation Stack Name: " + stackName); String templateBody = getTemplateBody(cfClient, stackName); Stack stack = getStack(cfClient, stackName); // If passed additional parameters, update them List<Parameter> parameters = stack.getParameters(); if (stackParameters != null && !stackParameters.isEmpty()) { List<Parameter> tmpParams = new ArrayList<Parameter>(); // Add Existing Parameters we haven't locally overwritten for (Parameter oldParam : parameters) { String oldKey = oldParam.getParameterKey(); if (!stackParameters.containsKey(oldKey)) { tmpParams.add(oldParam); } } // Add Overwrite parameters for (String key : stackParameters.keySet()) { Parameter newParam = new Parameter(); newParam.setParameterKey(key); newParam.setParameterValue(stackParameters.get(key)); tmpParams.add(newParam); } parameters = tmpParams; } // Update the Stack UpdateStackRequest updateStackRequest = new UpdateStackRequest(); updateStackRequest.setStackName(stackName); updateStackRequest.setTemplateBody(templateBody); updateStackRequest.setParameters(parameters); updateStackRequest.setCapabilities(stack.getCapabilities()); try { getLog().info("Updating Cloud Formation Stack..."); cfClient.updateStack(updateStackRequest); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Update Cloud Formation Stack", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Update Cloud Formation Stack", e); } getLog().info("Cloud Formation Stack " + stackName + "is now updating..."); } getLog().info("All stacks have been updated. Complete."); }
From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java
License:Apache License
protected String getTemplateBody(AmazonCloudFormationClient cfClient, String stackName) throws MojoExecutionException { String templateBody = null;/*w ww .j a v a2 s. c o m*/ try { GetTemplateRequest getTemplateRequest = new GetTemplateRequest(); getTemplateRequest.setStackName(stackName); getLog().info("Getting Cloud Formation Stack Template..."); GetTemplateResult getTemplateResult = cfClient.getTemplate(getTemplateRequest); if (getTemplateResult == null) { throw new MojoExecutionException("[NULL] Could Not Get Cloud Formation Stack Template"); } templateBody = getTemplateResult.getTemplateBody(); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Get Cloud Formation Stack Template", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Get Cloud Formation Stack Template", e); } return templateBody; }
From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java
License:Apache License
protected Stack getStack(AmazonCloudFormationClient cfClient, String stackName) throws MojoExecutionException { Stack stack = null;/*from w ww. j a va 2 s . c om*/ try { DescribeStacksRequest describeStacksRequest = new DescribeStacksRequest(); describeStacksRequest.setStackName(stackName); getLog().info("Getting Cloud Formation Stack Details..."); DescribeStacksResult describeStacksResult = cfClient.describeStacks(describeStacksRequest); if (describeStacksResult == null || describeStacksResult.getStacks() == null || describeStacksResult.getStacks().isEmpty()) { throw new MojoExecutionException("[NULL] Could Not Get Cloud Formation Stack Details"); } stack = describeStacksResult.getStacks().get(0); } catch (AmazonServiceException e) { throw new MojoExecutionException("[SERVICE] Could Not Get Cloud Formation Stack Details", e); } catch (AmazonClientException e) { throw new MojoExecutionException("[CLIENT] Could Not Get Cloud Formation Stack Details", e); } return stack; }
From source file:com.cleanenergyexperts.aws.cf.CloudFormationMojo.java
License:Apache License
protected AWSCredentials getAWSCredentials() throws MojoExecutionException { /*if (settings != null && serverId != null) { Server server = settings.getServer(serverId); if (server != null) {//w w w .ja va2 s . c om accessKey = server.getUsername().trim(); secretKey = server.getPassword().trim(); // TODO: Decrypt https://bitbucket.org/aldrinleal/beanstalker/src/d72b183f832cd81c670ca1e4ae764868cdfd16b9/beanstalker-common/src/main/java/br/com/ingenieux/mojo/aws/AbstractAWSMojo.java?at=default } }*/ if (accessKey == null || secretKey == null || accessKey.isEmpty() || secretKey.isEmpty()) { throw new MojoExecutionException("Missing either accessKey and secretKey."); } return new BasicAWSCredentials(accessKey, secretKey); }