List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptor getGroupId
public String getGroupId()
From source file:com.chaschev.install.InstallMojo.java
License:Apache License
private String sudoInstallationSupportingScript(String jarPath, String appLaunchingString) { String script;/*from www . ja v a 2 s .co 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 www . j av a 2 s . co m } } } PluginDescriptor currentPlugin = context.getPlugin(); execMojo(MagicGoals.ASSEMBLY_SINGLE, // configuration(elementArray(config)), // singleDependency(currentPlugin.getGroupId(), currentPlugin.getArtifactId(), currentPlugin.getVersion())); }
From source file:com.github.shyiko.jwarpack.maven.PackMojo.java
License:Apache License
private File getESJar() throws MojoExecutionException { if (serverLauncherJar != null) { return serverLauncherJar; }//from w w w. j a va2 s . c o m String key = null; PluginDescriptor pluginDescriptor = getPluginDescriptor(); Plugin plugin = findPlugin(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId()); for (Object o : plugin.getDependencies()) { Dependency dependency = (Dependency) o; String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); if (groupId.startsWith(ES_GROUP_PREFIX) && artifactId.startsWith(ES_ARTIFACT_PREFIX)) { if (key != null) { throw new MojoExecutionException("Multiple " + ES_ARTIFACT_PREFIX + " artifacts found. " + "Please check <plugin><dependencies>...</dependencies></plugin>."); } key = groupId + ":" + artifactId; } } if (key == null) { throw new MojoExecutionException("No " + ES_ARTIFACT_PREFIX + " artifacts found. " + "Please add one inside <plugin><dependencies>...</dependencies></plugin>."); } Artifact artifact = (Artifact) pluginDescriptor.getArtifactMap().get(key); return artifact.getFile(); }
From source file:com.github.shyiko.jwarpack.maven.PackMojo.java
License:Apache License
private File getAppWar() throws MojoExecutionException { if (applicationWar != null) { return applicationWar; }/* w ww. j a v a 2 s . c om*/ String key = null; PluginDescriptor pluginDescriptor = getPluginDescriptor(); Plugin plugin = findPlugin(pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId()); for (Object o : plugin.getDependencies()) { Dependency dependency = (Dependency) o; if ("war".equals(dependency.getType())) { if (key != null) { throw new MojoExecutionException("Multiple WAR artifacts found. " + "Please check <plugin><dependencies>...</dependencies></plugin>."); } key = dependency.getGroupId() + ":" + dependency.getArtifactId(); } } if (key == null) { throw new MojoExecutionException("No artifacts with <type>war</type> found. " + "Please add one inside <plugin><dependencies>...</dependencies></plugin>."); } Artifact artifact = (Artifact) pluginDescriptor.getArtifactMap().get(key); return artifact.getFile(); }
From source file:com.googlecode.cmakemavenproject.GenerateMojo.java
License:Apache License
@Override public void execute() throws MojoExecutionException { try {/*from w w w. j a va 2 s .c om*/ 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.AgentDependencies.java
License:Apache License
static AgentDependencies init(PluginDescriptor pluginDescriptor) throws MojoExecutionException { String pluginGroupId = pluginDescriptor.getGroupId(); String pluginArtifactId = pluginDescriptor.getArtifactId(); List<ExpectedDependency> expectedDependencies = Arrays.asList( new ExpectedDependency(pluginGroupId, "promagent-agent"), new ExpectedDependency(pluginGroupId, "promagent-internal"), new ExpectedDependency(pluginGroupId, "promagent-api"), new ExpectedDependency("io.prometheus", "simpleclient_common"), new ExpectedDependency("io.prometheus", "simpleclient"), new ExpectedDependency("net.bytebuddy", "byte-buddy"), new ExpectedDependency("commons-io", "commons-io")); List<Artifact> actualDependencies = resolveVersions(pluginDescriptor, pluginArtifactId, expectedDependencies);/*from w w w. j a v a 2 s. c o m*/ failUnlessComplete(actualDependencies, expectedDependencies, pluginArtifactId); return new AgentDependencies(pluginGroupId, actualDependencies); }
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(); }// w w w.ja v a 2s.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.apache.tuscany.sdo.plugin.GeneratorMojo.java
License:Apache License
public void execute() throws MojoExecutionException { // check for schemaFiles parameter first, if properties are not set, use // global property if (null != schemaFiles) { for (int i = 0; i < schemaFiles.length; ++i) { SchemaFileOption sf = schemaFiles[i]; if (null == sf.getTargetDirectory()) { sf.setTargetDirectory(targetDirectory); }/*w ww . j a va 2 s. com*/ if (null == sf.getJavaPackage()) { sf.setJavaPackage(javaPackage); } if (null == sf.getSchemaNamespace()) { sf.setSchemaNamespace(schemaNamespace); } if (null == sf.isNoInterfaces()) { sf.setNoInterfaces(noInterfaces); } if (null == sf.isNoContainment()) { sf.setNoContainment(noContainment); } if (null == sf.isNoNotification()) { sf.setNoNotification(noNotification); } if (null == sf.isNoUnsettable()) { sf.setNoUnsettable(noUnsettable); } if (null == sf.isGenerateLoader()) { sf.setGenerateLoader(generateLoader); } if (null == sf.isGenerateSwitch()) { sf.setGenerateSwitch(generateSwitch); } // if (null == sf.getCompilerSourceRoots()) { // sf.setCompilerSourceRoots(compileSourceRoots); // } if (null == sf.isInterfaceDataObject()) { sf.setInterfaceDataObject(interfaceDataObject); } if (sf.getFileName() == null || sf.getFileName().length() == 0) { throw new MojoExecutionException("no fileName specfied for schema."); } if (!sf.getFileName().canRead() || !sf.getFileName().isFile()) { throw new MojoExecutionException("file can not be read:" + sf.getFileName()); } } } else { if (schemaFile == null) { File[] files = new File(schemaDir).listFiles(FILTER); schemaFiles = new SchemaFileOption[files.length]; for (int i = files.length - 1; i > -1; --i) { schemaFiles[i] = new SchemaFileOption(); schemaFiles[i].setFileName(files[i]); schemaFiles[i].setJavaPackage(javaPackage); // schemaFiles[i].setCompilerSourceRoots(compileSourceRoots); schemaFiles[i].setGenerateLoader(generateLoader); schemaFiles[i].setGenerateSwitch(generateSwitch); schemaFiles[i].setNoContainment(noContainment); schemaFiles[i].setInterfaceDataObject(interfaceDataObject); schemaFiles[i].setNoInterfaces(noInterfaces); schemaFiles[i].setNoNotification(noNotification); schemaFiles[i].setNoUnsettable(noUnsettable); schemaFiles[i].setPrefix(prefix); schemaFiles[i].setTargetDirectory(targetDirectory); schemaFiles[i].setSchemaNamespace(schemaNamespace); } } else { schemaFiles = new SchemaFileOption[] { new SchemaFileOption() }; schemaFiles[0].setFileName(schemaFile); schemaFiles[0].setJavaPackage(javaPackage); // schemaFiles[0].setCompilerSourceRoots(compileSourceRoots); schemaFiles[0].setGenerateLoader(generateLoader); schemaFiles[0].setGenerateSwitch(generateSwitch); schemaFiles[0].setNoContainment(noContainment); schemaFiles[0].setInterfaceDataObject(interfaceDataObject); schemaFiles[0].setNoInterfaces(noInterfaces); schemaFiles[0].setNoNotification(noNotification); schemaFiles[0].setNoUnsettable(noUnsettable); schemaFiles[0].setPrefix(prefix); schemaFiles[0].setTargetDirectory(targetDirectory); schemaFiles[0].setSchemaNamespace(schemaNamespace); } } for (int i = 0; i < schemaFiles.length; i++) { File file = schemaFiles[i].getFileName(); File marker = new File(schemaFiles[i].getTargetDirectory(), ".gen#" + file.getName()); if (file.lastModified() > marker.lastModified()) { getLog().info("Generating SDO interfaces from " + file); int genOptions = 0; if (schemaFiles[i].isNoInterfaces() != null && schemaFiles[i].isNoInterfaces().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_INTERFACES; } if (schemaFiles[i].isNoContainment() != null && schemaFiles[i].isNoContainment().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_CONTAINMENT; } if (schemaFiles[i].isNoNotification() != null && schemaFiles[i].isNoNotification().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_NOTIFICATION; } if (schemaFiles[i].isGenerateLoader() != null && schemaFiles[i].isGenerateLoader().booleanValue()) { genOptions |= JavaGenerator.OPTION_GENERATE_LOADER; } if (schemaFiles[i].isNoUnsettable() != null && schemaFiles[i].isNoUnsettable().booleanValue()) { genOptions |= JavaGenerator.OPTION_NO_UNSETTABLE; } if (schemaFiles[i].isGenerateSwitch() != null && schemaFiles[i].isGenerateSwitch().booleanValue()) { genOptions |= JavaGenerator.OPTION_GENERATE_SWITCH; } if (schemaFiles[i].isInterfaceDataObject() != null && schemaFiles[i].isInterfaceDataObject().booleanValue()) { genOptions |= JavaGenerator.OPTION_INTERFACE_DO; } XSD2JavaGenerator.generateFromXMLSchema(file.toString(), schemaFiles[i].getSchemaNamespace(), schemaFiles[i].getTargetDirectory(), schemaFiles[i].getJavaPackage(), schemaFiles[i].getPrefix(), genOptions); } try { marker.createNewFile(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage() + "'" + marker.getAbsolutePath() + "'", e); } marker.setLastModified(System.currentTimeMillis()); } targetDirectory = targetDirectory.replace('/', File.separatorChar); // FIXME: [rfeng] Workaround to figure out the current execution phase MojoDescriptor descriptor = (MojoDescriptor) mojos.get(0); PluginDescriptor pluginDescriptor = descriptor.getPluginDescriptor(); Map pluginMap = project.getBuild().getPluginsAsMap(); Plugin plugin = (Plugin) pluginMap .get(pluginDescriptor.getGroupId() + ":" + pluginDescriptor.getArtifactId()); // How to get the current execution id? for (Iterator i = plugin.getExecutions().iterator(); i.hasNext();) { PluginExecution execution = (PluginExecution) i.next(); String phase = execution.getPhase(); if (phase != null && phase.indexOf("-test-") != -1) { project.addTestCompileSourceRoot(targetDirectory); } else { project.addCompileSourceRoot(targetDirectory); } } }
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; }/* w ww.j a v a2 s .co 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; }