List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptor getVersion
public String getVersion()
From source file:com.chaschev.install.InstallMojo.java
License:Apache License
private String sudoInstallationSupportingScript(String jarPath, String appLaunchingString) { String script;/* www . j ava 2s. c o m*/ boolean unix = IS_OS_UNIX; PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); if (unix) { appLaunchingString = appLaunchingString + " $*"; script = MessageFormat.format( "" + "{0} -cp \"{1}\" {2} SMOKE_TEST_HUH 2> /dev/null\n" + "\n" + "rc=$?\n" + "\n" + "if [[ $rc != 0 ]] ; then\n" + " mvn -U {4}:{5}:{6}:fetch\n" + " {3}\n" + " exit $rc\n" + "fi\n" + "\n" + "{3}\n", javaExePath(), jarPath, Runner.class.getName(), appLaunchingString, desc.getGroupId(), desc.getArtifactId(), desc.getVersion()); } else { //add quotes for "Program Files" case appLaunchingString = '"' + substringBefore(appLaunchingString, " ") + "\" " + substringAfter(appLaunchingString, " "); appLaunchingString = "@" + appLaunchingString + " %*"; script = MessageFormat.format( "" + "@{0} -cp \"{1}\" {2} SMOKE_TEST_HUH 2> nul\n" + "@IF ERRORLEVEL 1 GOTO nok\n" + "{3}\n" + "@goto leave\n\n" + "" + ":nok\n" + "mvn -U {4}:{5}:{6}:fetch\n" + "{3}\n" + "@goto leave\n\n" + "" + ":leave\n", javaExePath(), jarPath, Runner.class.getName(), appLaunchingString, desc.getGroupId(), desc.getArtifactId(), desc.getVersion()); } return script; }
From source file:com.github.emenaceb.appjar.maven.executor.AssemblyExecutor.java
License:Apache License
protected void packageWithAssembly(String ref, Element... elements) throws MojoExecutionException { List<Element> config = new ArrayList<Element>(); config.add(element("descriptorRefs", element("descriptorRef", ref))); if (elements != null) { for (Element e : elements) { if (e != null) { config.add(e);/*from ww w .j a v a 2 s. c om*/ } } } PluginDescriptor currentPlugin = context.getPlugin(); execMojo(MagicGoals.ASSEMBLY_SINGLE, // configuration(elementArray(config)), // singleDependency(currentPlugin.getGroupId(), currentPlugin.getArtifactId(), currentPlugin.getVersion())); }
From source file:com.googlecode.cmakemavenproject.GenerateMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { try {/*from www. java 2 s . c o m*/ PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); String groupId = pluginDescriptor.getGroupId(); String version = pluginDescriptor.getVersion(); String classifier = getClassifier(); if (!targetPath.exists() && !targetPath.mkdirs()) throw new MojoExecutionException("Cannot create " + targetPath.getAbsolutePath()); if (classifier == null) { String os = System.getProperty("os.name"); String arch = System.getProperty("os.arch"); if (os.toLowerCase().startsWith("windows")) classifier = "windows"; else if (os.toLowerCase().startsWith("linux")) if (arch.equals("x86_64") || arch.equals("amd64")) classifier = "linux64"; else if (arch.equals("i386")) classifier = "linux32"; else throw new MojoExecutionException("Unsupported Linux arch: " + arch); else if (os.toLowerCase().startsWith("mac")) if (arch.equals("x86_64")) classifier = "mac64"; else throw new MojoExecutionException("Unsupported Mac arch: " + arch); else throw new MojoExecutionException("Unsupported os.name: " + os); } File cmakeDir = new File(project.getBuild().getDirectory(), "dependency/cmake"); String binariesArtifact = "cmake-binaries"; Element groupIdElement = new Element("groupId", groupId); Element artifactIdElement = new Element("artifactId", binariesArtifact); Element versionElement = new Element("version", version); Element classifierElement = new Element("classifier", classifier); Element outputDirectoryElement = new Element("outputDirectory", cmakeDir.getAbsolutePath()); Element artifactItemElement = new Element("artifactItem", groupIdElement, artifactIdElement, versionElement, classifierElement, outputDirectoryElement); Element artifactItemsItem = new Element("artifactItems", artifactItemElement); Xpp3Dom configuration = MojoExecutor.configuration(artifactItemsItem); ExecutionEnvironment environment = MojoExecutor.executionEnvironment(project, session, pluginManager); Plugin dependencyPlugin = MojoExecutor.plugin("org.apache.maven.plugins", "maven-dependency-plugin", "2.8"); MojoExecutor.executeMojo(dependencyPlugin, "unpack", configuration, environment); ProcessBuilder processBuilder = new ProcessBuilder(new File(cmakeDir, "bin/cmake").getAbsolutePath(), "-G", generator).directory(targetPath); if (options != null) processBuilder.command().addAll(options); processBuilder.command().add(sourcePath.getAbsolutePath()); Map<String, String> env = processBuilder.environment(); if (environmentVariables != null) env.putAll(environmentVariables); Log log = getLog(); if (log.isDebugEnabled()) { log.debug("sourcePath: " + sourcePath); log.debug("targetPath: " + targetPath); log.debug("environment: " + processBuilder.environment()); log.debug("command-line: " + processBuilder.command()); } int returnCode = Mojos.waitFor(processBuilder); if (returnCode != 0) throw new MojoExecutionException("Return code: " + returnCode); } catch (InterruptedException e) { throw new MojoExecutionException("", e); } catch (IOException e) { throw new MojoExecutionException("", e); } }
From source file:hudson.gridmaven.PluginName.java
License:Open Source License
public PluginName(PluginDescriptor pd) { this(pd.getGroupId(), pd.getArtifactId(), pd.getVersion()); }
From source file:io.promagent.plugin.ManifestTransformer.java
License:Apache License
ManifestTransformer(PluginDescriptor pluginDescriptor) { pluginArtifactId = pluginDescriptor.getArtifactId(); pluginVersion = pluginDescriptor.getVersion(); }
From source file:io.sarl.maven.docs.AbstractDocumentationMojo.java
License:Apache License
private Properties createGeneratorProperties() { final Properties props = new Properties(); final PluginDescriptor descriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); //$NON-NLS-1$ props.put("generator.name", descriptor.getArtifactId()); //$NON-NLS-1$ props.put("generator.version", descriptor.getVersion()); //$NON-NLS-1$ return props; }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
private Map<String, MojoDescriptor> readPluginXml(DefaultPlexusContainer container) throws Exception { Map<String, MojoDescriptor> mojoDescriptors = new HashMap<String, MojoDescriptor>(); Enumeration<URL> resources = getClass().getClassLoader().getResources(PATH_PLUGINXML); while (resources.hasMoreElements()) { InputStream is = resources.nextElement().openStream(); if (is == null) { return Collections.emptyMap(); }/*from w w w.j a v a 2 s.c o m*/ XmlStreamReader reader = new XmlStreamReader(is); @SuppressWarnings("rawtypes") Map contextData = container.getContext().getContextData(); @SuppressWarnings("unchecked") InterpolationFilterReader interpolationFilterReader = new InterpolationFilterReader( new BufferedReader(reader), contextData); PluginDescriptor pluginDescriptor = new PluginDescriptorBuilder().build(interpolationFilterReader); Artifact artifact = container.lookup(RepositorySystem.class) // .createArtifact(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId(), pluginDescriptor.getVersion(), ".jar"); artifact.setFile(getPluginArtifactFile()); pluginDescriptor.setPluginArtifact(artifact); pluginDescriptor.setArtifacts(Arrays.asList(artifact)); for (ComponentDescriptor<?> desc : pluginDescriptor.getComponents()) { container.addComponentDescriptor(desc); } for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) { // TODO decide how to handle duplicate goals // this is possible when one plugin extends another // for example, Tycho 'compile' goal is an extension of standard maven 'compile' mojoDescriptors.put(mojoDescriptor.getGoal(), mojoDescriptor); } } return mojoDescriptors; }
From source file:org.fornax.toolsupport.maven2.WorkflowMojo.java
License:Apache License
public void execute() throws MojoExecutionException { MojoWorkflowRunner wfr = null;//from ww w. j a v a 2 s.co m Map<String, String> params = new HashMap<String, String>(); final PluginDescriptor d = getPluginContext() != null ? (PluginDescriptor) getPluginContext().get("pluginDescriptor") : null; final String version = d != null ? " V" + d.getVersion() : ""; getLog().info("Fornax Model Workflow Maven2 Plugin" + version); // Check workflowEngine parameter if (!WFENGINE_OAW.equals(workflowEngine) && !WFENGINE_MWE.equals(workflowEngine) && !WFENGINE_MWE2.equals(workflowEngine)) { throw new IllegalArgumentException("Illegal value specified for parameter workflowEngine"); } wfr = new MojoWorkflowRunner(); wfr.setLog(getLog()); if (skip || "true".equals(System.getProperty(PROPERTY_OMIT_EXECUTION))) { getLog().info("Omitting workflow execution."); return; } if (force || "true".equalsIgnoreCase(System.getProperty(PROPERTY_FORCE_EXECUTION))) { getLog().info("Forced workflow execution."); File timeStampFile = getTimestampFile(); if (timeStampFile != null) { timeStampFile.delete(); } } populateWorkflowRealm(); Set<String> changedFiles = changedFiles(); if (changedFiles == null || !changedFiles.isEmpty()) { addChangedFilesToSystemProperties(changedFiles); extendCurrentClassloader(wfr); params.put("basedir", project.getBasedir().getPath()); params.put("outlet.src.dir", getNormalizedFilePath(outletSrcDir)); params.put("outlet.res.dir", getNormalizedFilePath(outletResDir)); params.put("outlet.src.once.dir", getNormalizedFilePath(outletSrcOnceDir)); params.put("outlet.res.once.dir", getNormalizedFilePath(outletResOnceDir)); params.put("outlet.src.test.dir", getNormalizedFilePath(outletSrcTestDir)); params.put("outlet.res.test.dir", getNormalizedFilePath(outletResTestDir)); params.put("outlet.src.test.once.dir", getNormalizedFilePath(outletSrcTestOnceDir)); params.put("outlet.res.test.once.dir", getNormalizedFilePath(outletResTestOnceDir)); params.put("outlet.src.protected.dir", getNormalizedFilePath(outletSrcProtectedDir)); params.put("outlet.res.protected.dir", getNormalizedFilePath(outletResTestProtectedDir)); params.put("outlet.src.test.protected.dir", getNormalizedFilePath(outletSrcProtectedDir)); params.put("outlet.res.test.protected.dir", getNormalizedFilePath(outletResTestProtectedDir)); if (properties != null && properties.size() > 0) { params.putAll(properties); } String prevUserDir = System.getProperty("user.dir"); // Setting working dir of forked jvm works differently in different OS. // changing user.dir is necessary for (at least) Mac and Linux // We use org.apache.tools.ant.taskdefs.Java (and Execute) to create jvm. // Note that by setting user.dir the to the same as project.basedir then Java.setDir // will not be used, and therfore it is important to set it to something slightly // different (ugly, I know) System.setProperty("user.dir", project.getBasedir().getPath() + System.getProperty("file.separator") + "."); // Initialize MojoWorkflowRunner // if (progressMonitorClass == null) { // if (WFENGINE_OAW.equals(workflowEngine)) { // progressMonitorClass = OAW_PROGRESSMONITOR; // } else if (WFENGINE_MWE.equals(workflowEngine)) { // progressMonitorClass = MWE_PROGRESSMONITOR; // } // } if (workflowRunnerClass == null) { if (WFENGINE_OAW.equals(workflowEngine)) { workflowRunnerClass = OAW_WORKFLOWRUNNER; } else if (WFENGINE_MWE.equals(workflowEngine)) { workflowRunnerClass = MWE_WORKFLOWRUNNER; } else if (WFENGINE_MWE2.equals(workflowEngine)) { workflowRunnerClass = MWE2_WORKFLOWRUNNER; } } // Set properties depending on workflow engine if (WFENGINE_OAW.equals(workflowEngine) || WFENGINE_MWE.equals(workflowEngine)) { // Prove for default workflowDescriptor. If workflowEngine is // set to "mwe" // replace default value by "workflow.mwe" if ("workflow.oaw".equals(workflowDescriptor) && "mwe".equals(workflowEngine)) { workflowDescriptor = "workflow.mwe"; } if (getWorkflowDescriptorRoot() == null) { throw new MojoExecutionException( "Could not find the Workflow-Descriptor \"" + workflowDescriptor + "\"."); } } if (WFENGINE_MWE2.equals(workflowEngine)) { if (!jvmSettings.isFork()) { getLog().debug("Setting fork to true for MWE2."); jvmSettings.setFork(true); } } if (jvmSettings.isFork()) { getLog().info("Executing workflow in forked mode."); } initJavaTask(wfr, params); // //////////////////////////////////////////////////////////////// // Execute the workflow boolean success = false; try { if (securitySettings != null) { javaTask.createPermissions().setSecurityManager(); } success = wfr.run(); // look if the log stream detected errors if (success && mavenLogOutputStream != null) { success = !mavenLogOutputStream.hasErrors(); } if (success) { createTimestampFile(); getLog().info("Workflow '" + workflowDescriptor + "' finished."); } else { throw new MojoExecutionException("Workflow execution failed."); } } catch (RuntimeException e) { success = false; } finally { System.setProperty("user.dir", prevUserDir); if (securitySettings != null) { javaTask.createPermissions().restoreSecurityManager(); } } // //////////////////////////////////////////////////////////////// } if (project != null) { try { extendCompileSourceRoot(); extendResources(outletResDir, false); extendResources(outletResOnceDir, false); extendResources(outletResTestDir, true); extendResources(outletResTestOnceDir, true); extendResources(outletResProtectedDir, false); extendResources(outletResTestProtectedDir, true); } catch (Exception ex) { throw new MojoExecutionException("Could not extend the project's compile path.", ex); } } if (!isDefaultOawResourceDirManaged) { for (int i = 0; i < project.getBuild().getResources().size(); i++) { Resource resource = (Resource) project.getBuild().getResources().get(i); if (resource.getDirectory().equalsIgnoreCase(defaultOawResourceDir)) { project.getBuild().removeResource(resource); } } } }
From source file:org.kantega.reststop.maven.CreateMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException, MojoFailureException { MavenProject parent = mavenProject.getParent(); PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); Map<String, String> options = getOptions(); String pack = options.get("package"); String artifactId = options.get("artifactId"); File rootDir = new File(artifactId); File rootPom = new File(rootDir, "pom.xml"); File webappDir = new File(rootDir, "webapp"); File webappPom = new File(webappDir, "pom.xml"); try {/*from w w w . j av a 2 s. c om*/ Map<String, String> tokens = new HashMap<>(); tokens.put("${groupId}", options.get("groupId")); tokens.put("${artifactId}", artifactId); tokens.put("${reststopVersion}", pluginDescriptor.getVersion()); // root createMavenModule(tokens, getClass().getResourceAsStream("dist/template-plugin-pom.xml"), rootPom); tokens.remove("${reststopVersion}"); // plugins File pluginsDir = new File(rootDir, "plugins"); createMavenModule(tokens, getClass().getResourceAsStream("dist/template-plugin-plugins-pom.xml"), new File(pluginsDir, "pom.xml")); // api plugin File apiPluginDir = new File(pluginsDir, "api"); Map<String, String> tokensApi = new HashMap<>(); tokensApi.put("${groupId}", options.get("groupId")); tokensApi.put("${name}", "api"); tokensApi.put("${artifactId}", artifactId); tokensApi.put("${rootArtifactId}", artifactId); createMavenModule(tokensApi, getClass().getResourceAsStream("dist/template-newplugin-pom.xml"), new File(apiPluginDir, "pom.xml")); new File(apiPluginDir, "src/main/resources").mkdirs(); new File(apiPluginDir, "src/test/resources").mkdirs(); File sourceDir = new File(apiPluginDir, "src/main/java"); sourceDir.mkdirs(); List<String> methods = new ArrayList<>(); methods.add("getMessage"); createInterface("Greeting", methods, sourceDir, pack); // helloworld plugin File pluginDir = new File(pluginsDir, "helloworld"); createMavenModule(tokens, getClass().getResourceAsStream("dist/template-plugin-plugin-pom.xml"), new File(pluginDir, "pom.xml")); List<String> classNames = asList("ExamplePlugin.java", "HelloworldResource.java", "Hello.java"); createClasses(pack, classNames, new File(pluginDir, "src/main/java/")); List<String> testClassNames = asList("HelloworldResourceTest.java"); createClasses(pack, testClassNames, new File(pluginDir, "src/test/java/")); new File(pluginDir, "src/main/resources").mkdirs(); new File(pluginDir, "src/test/resources").mkdirs(); // webapp createMavenModule(tokens, getClass().getResourceAsStream("dist/template-plugin-webapp-pom.xml"), webappPom); File webappDirTest = new File(new File(new File(webappDir, "src"), "test"), "jetty"); webappDirTest.mkdirs(); String webOverride = IOUtils.toString(getClass().getResourceAsStream("dist/template-context.xml"), "utf-8"); Files.write(new File(webappDirTest, "context.xml").toPath(), webOverride.getBytes("utf-8")); File webinfDir = webappDir.toPath().resolve("src").resolve("main").resolve("webapp").resolve("WEB-INF") .toFile(); webinfDir.mkdirs(); String webXml = IOUtils.toString(getClass().getResourceAsStream("dist/template-web.xml"), "utf-8"); webXml = webXml.replace("${artifactId}", artifactId); Files.write(new File(webinfDir, "web.xml").toPath(), webXml.getBytes("utf-8")); File config = new File(new File(webappDir, "src/config/"), artifactId + ".conf"); config.getParentFile().mkdirs(); Files.write(config.toPath(), "greeting=Hello".getBytes("utf-8")); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } InvocationRequest request = new DefaultInvocationRequest(); request.setPomFile(rootPom); request.setGoals(asList("clean", "install")); try { invoker.execute(request); } catch (MavenInvocationException e) { throw new MojoExecutionException("Failed executing reststop:run on created project", e); } InvocationRequest request2 = new DefaultInvocationRequest(); request2.setPomFile(webappPom); request2.setGoals(asList("jetty:run")); try { invoker.execute(request2); } catch (MavenInvocationException e) { throw new MojoExecutionException("Failed executing reststop:run on created project", e); } }
From source file:org.teiid.plugin.maven.GeneratorMojo.java
License:Open Source License
private File getWildflyDist() { String artifactId = "teiid"; //$NON-NLS-1$ String classifier = "wildfly-dist"; //$NON-NLS-1$ String type = "zip"; //$NON-NLS-1$ PluginDescriptor plugin = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); //$NON-NLS-1$ String groupId = plugin.getGroupId(); String version = plugin.getVersion(); // String version = "9.1.0.Alpha2"; String line = "-"; String artifact = artifactId + line + version + line + classifier + "." + type; ArtifactRepository jbossDeveloper = null; for (ArtifactRepository repository : remoteRepositories) { if (repository.getUrl().startsWith("https://repository.jboss.org/nexus/content/groups/developer")) { //$NON-NLS-1$ jbossDeveloper = repository; break; }//from w w w . jav a 2s .c o m } groupId = groupId.replaceAll("\\.", File.separator) + File.separator + artifactId + File.separator; //$NON-NLS-1$ String remotePath = groupId + version + File.separator + artifact; getLog().info("Download " + artifact + " from " + jbossDeveloper.getUrl()); //$NON-NLS-1$ //$NON-NLS-2$ File destination = null; try { destination = File.createTempFile(artifactId, "." + type); destination.deleteOnExit(); repoSystem.retrieve(jbossDeveloper, destination, remotePath, new ArtifactTransferListener() { @Override public boolean isShowChecksumEvents() { return false; } @Override public void setShowChecksumEvents(boolean showChecksumEvents) { } @Override public void transferInitiated(ArtifactTransferEvent transferEvent) { } @Override public void transferStarted(ArtifactTransferEvent transferEvent) { getLog().info("download start"); //$NON-NLS-1$ } @Override public void transferProgress(ArtifactTransferEvent transferEvent) { } @Override public void transferCompleted(ArtifactTransferEvent transferEvent) { getLog().info("download completed"); //$NON-NLS-1$ } }); } catch (IOException | ArtifactTransferFailedException | ArtifactDoesNotExistException e) { } return destination; }