Example usage for org.apache.maven.plugin.descriptor PluginDescriptor getArtifactId

List of usage examples for org.apache.maven.plugin.descriptor PluginDescriptor getArtifactId

Introduction

In this page you can find the example usage for org.apache.maven.plugin.descriptor PluginDescriptor getArtifactId.

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:com.chaschev.install.InstallMojo.java

License:Apache License

private String sudoInstallationSupportingScript(String jarPath, String appLaunchingString) {
    String script;//from  ww w . j  a  va  2s  .  com

    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   w w  w  .  ja  va2 s  .c  o  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 v a 2 s.  com
    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;
    }//from w w w.ja v a 2 s .  co m
    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: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 ww .  ja  va  2 s  . com*/
    failUnlessComplete(actualDependencies, expectedDependencies, pluginArtifactId);
    return new AgentDependencies(pluginGroupId, actualDependencies);
}

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. ja  v  a2s.  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 w  w  .j av a 2 s . co  m*/
            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);
        }
    }
}