Java Code Examples for org.apache.maven.model.Model#getArtifactId()

The following examples show how to use org.apache.maven.model.Model#getArtifactId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuarkusJsonPlatformDescriptorResolver.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static String getGroupId(Model model) {
    if (model == null) {
        return null;
    }
    String groupId = model.getGroupId();
    if (groupId != null) {
        return groupId;
    }
    final Parent parent = model.getParent();
    if (parent != null) {
        groupId = parent.getGroupId();
        if (groupId != null) {
            return groupId;
        }
    }
    throw new IllegalStateException("Failed to determine the groupId for the POM of " + model.getArtifactId());
}
 
Example 2
Source File: QuarkusJsonPlatformDescriptorResolver.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static String getVersion(Model model) {
    if (model == null) {
        return null;
    }
    String version = model.getVersion();
    if (version != null) {
        return version;
    }
    final Parent parent = model.getParent();
    if (parent != null) {
        version = parent.getVersion();
        if (version != null) {
            return version;
        }
    }
    throw new IllegalStateException("Failed to determine the version for the POM of " + model.getArtifactId());
}
 
Example 3
Source File: GAV.java    From maven-git-versioning-extension with MIT License 6 votes vote down vote up
public static GAV of(Model model) {

        String groupId = model.getGroupId();
        String artifactId = model.getArtifactId();
        String version = model.getVersion();

        Parent parent = model.getParent();
        if (parent != null) {
            if (groupId == null) {
                groupId = parent.getGroupId();
            }
            if (version == null) {
                version = parent.getVersion();
            }
        }

        return new GAV(groupId, artifactId, version);
    }
 
Example 4
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private List<RemoteRepository> resolveCurrentProjectRepos(List<RemoteRepository> repos)
        throws BootstrapMavenException {
    final Model model = loadCurrentProjectModel();
    if (model == null) {
        return repos;
    }
    final Artifact projectArtifact = new DefaultArtifact(ModelUtils.getGroupId(model), model.getArtifactId(), "", "pom",
            ModelUtils.getVersion(model));
    final List<RemoteRepository> rawRepos;
    try {
        rawRepos = getRepositorySystem()
                .readArtifactDescriptor(getRepositorySystemSession(), new ArtifactDescriptorRequest()
                        .setArtifact(projectArtifact)
                        .setRepositories(repos))
                .getRepositories();
    } catch (ArtifactDescriptorException e) {
        throw new BootstrapMavenException("Failed to read artifact descriptor for " + projectArtifact, e);
    }
    return getRepositorySystem().newResolutionRepositories(getRepositorySystemSession(), rawRepos);
}
 
Example 5
Source File: CarnotzetModuleCoordinates.java    From carnotzet with Apache License 2.0 6 votes vote down vote up
public static CarnotzetModuleCoordinates fromPom(@NonNull Path pom) {
	Model result;
	try {
		BufferedReader in = new BufferedReader(Files.newBufferedReader(pom, StandardCharsets.UTF_8));
		MavenXpp3Reader reader = new MavenXpp3Reader();
		result = reader.read(in);
	}
	catch (XmlPullParserException | IOException e) {
		throw new CarnotzetDefinitionException(e);
	}
	String groupId = result.getGroupId();
	String version = result.getVersion();
	if (groupId == null) {
		groupId = result.getParent().getGroupId();
	}
	if (version == null) {
		version = result.getParent().getVersion();
	}
	return new CarnotzetModuleCoordinates(groupId, result.getArtifactId(), version, null);
}
 
Example 6
Source File: PomUpdater.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private String artifactId(Model model) {
	boolean parent = model.getArtifactId().endsWith("-parent");
	if (!parent) {
		return model.getArtifactId();
	}
	return model.getArtifactId().substring(0,
			model.getArtifactId().indexOf("-parent"));
}
 
Example 7
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the artifactId from a raw model, interpolating from the parent if necessary.
 *
 * @param model The model.
 * @return The artifactId.
 */
public static String getArtifactId( Model model )
{
    String sourceArtifactId = model.getArtifactId();
    if ( sourceArtifactId == null && model.getParent() != null )
    {
        sourceArtifactId = model.getParent().getArtifactId();
    }
    return sourceArtifactId;
}
 
Example 8
Source File: MavenRepositoryDeployer.java    From maven-repository-tools with Eclipse Public License 1.0 5 votes vote down vote up
public static Gav getCoordinates ( File pomFile ) throws Exception
{
    BufferedReader in = new BufferedReader( new FileReader( pomFile ) );
    MavenXpp3Reader reader = new MavenXpp3Reader();
    Model model = reader.read( in );
    // get coordinates and take care of inheritance and default
    String g = model.getGroupId();
    if ( StringUtils.isEmpty( g ) ) 
    {
        g = model.getParent().getGroupId();
    }
    String a = model.getArtifactId();
    if ( StringUtils.isEmpty( a ) ) 
    {
        a = model.getParent().getArtifactId();
    }
    String v = model.getVersion();
    if ( StringUtils.isEmpty( v ) ) 
    {
        v = model.getParent().getVersion();
    }
    String p = model.getPackaging();
    if ( StringUtils.isEmpty( p ) ) 
    {
        p = MavenConstants.JAR;
    }
    Gav gav = new Gav( g, a, v, p );
    return gav;
}
 
Example 9
Source File: MavenRunner.java    From app-runner with MIT License 5 votes vote down vote up
public void start(LineConsumer buildLogHandler, LineConsumer consoleLogHandler, Map<String, String> envVarsForApp, Waiter startupWaiter) throws ProjectCannotStartException {
    File pomFile = new File(projectRoot, "pom.xml");

    if (goals.isEmpty()) {
        log.info("No goals. Skipping maven build");

    } else {
        InvocationRequest request = new DefaultInvocationRequest()
            .setBatchMode(true)
            .setPomFile(pomFile)
            .setOutputHandler(buildLogHandler::consumeLine)
            .setErrorHandler(buildLogHandler::consumeLine)
            .setGoals(goals)
            .setBaseDirectory(projectRoot);


        log.info("Building maven project at " + fullPath(projectRoot));
        runRequest(request, javaHomeProvider);
        log.info("Build successful. Going to start app.");
    }

    Model model = loadPomModel(pomFile);
    String jarName = model.getArtifactId() + "-" + model.getVersion() + ".jar";

    File jar = new File(new File(projectRoot, "target"), jarName);
    if (!jar.isFile()) {
        throw new ProjectCannotStartException("Could not find the jar file at " + fullPath(jar));
    }

    CommandLine command = javaHomeProvider.commandLine(envVarsForApp)
        .addArgument("-Djava.io.tmpdir=" + envVarsForApp.get("TEMP"))
        .addArgument("-jar")
        .addArgument("target" + File.separator + jarName);

    watchDog = ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
}
 
Example 10
Source File: AbstractVersionsStep.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isReactorDependency(MavenProject project, Dependency dependency) {
  String groupId = dependency.getGroupId();
  String artifactId = dependency.getArtifactId();

  Model model = this.rawModels.getUnchecked(project);
  String reactorGroupId = model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId();
  String reactorArtifactId = model.getArtifactId();

  return Objects.equals(groupId, reactorGroupId) && Objects.equals(artifactId, reactorArtifactId);
}
 
Example 11
Source File: MavenUtils.java    From JobX with Apache License 2.0 5 votes vote down vote up
public String getArtifactId() {
    Model model = getCurrentModel();
    if (model == null) {
        return null;
    }
    return model.getArtifactId();
}
 
Example 12
Source File: LocalProject.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private LocalProject(Model rawModel, LocalWorkspace workspace) throws BootstrapMavenException {
    this.rawModel = rawModel;
    this.dir = rawModel.getProjectDirectory().toPath();
    this.workspace = workspace;
    this.groupId = ModelUtils.getGroupId(rawModel);
    this.artifactId = rawModel.getArtifactId();

    final String rawVersion = ModelUtils.getRawVersion(rawModel);
    final boolean rawVersionIsUnresolved = ModelUtils.isUnresolvedVersion(rawVersion);
    String resolvedVersion = rawVersionIsUnresolved ? ModelUtils.resolveVersion(rawVersion, rawModel) : rawVersion;

    if (workspace != null) {
        workspace.addProject(this, rawModel.getPomFile().lastModified());
        if (rawVersionIsUnresolved) {
            if (resolvedVersion == null) {
                resolvedVersion = workspace.getResolvedVersion();
                if (resolvedVersion == null) {
                    throw UnresolvedVersionException.forGa(groupId, artifactId, rawVersion);
                }
            } else {
                workspace.setResolvedVersion(resolvedVersion);
            }
        }
    } else if (resolvedVersion == null) {
        throw UnresolvedVersionException.forGa(groupId, artifactId, rawVersion);
    }

    this.version = resolvedVersion;
}
 
Example 13
Source File: BootstrapMavenContext.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public AppArtifact getCurrentProjectArtifact(String extension) throws BootstrapMavenException {
    if (currentProject != null) {
        return currentProject.getAppArtifact(extension);
    }
    final Model model = loadCurrentProjectModel();
    if (model == null) {
        return null;
    }
    return new AppArtifact(ModelUtils.getGroupId(model), model.getArtifactId(), "", extension,
            ModelUtils.getVersion(model));
}
 
Example 14
Source File: MavenUtil.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static String getArtifactFile(final File dir) {
  try {
    final Model model = getModel(new File(dir, "pom.xml"));
    final String version = model.getVersion() != null ? model.getVersion() : model.getParent().getVersion();
    return model.getArtifactId() + "-" + version + ".jar";
  }
  catch (final IOException | XmlPullParserException e) {
    throw new IllegalStateException(e);
  }
}
 
Example 15
Source File: CamelQuarkusExtension.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public static CamelQuarkusExtension read(Path runtimePomXmlPath) {
    try (Reader runtimeReader = Files.newBufferedReader(runtimePomXmlPath, StandardCharsets.UTF_8)) {
        final MavenXpp3Reader rxppReader = new MavenXpp3Reader();
        final Model runtimePom = rxppReader.read(runtimeReader);
        final List<Dependency> deps = runtimePom.getDependencies();

        final String aid = runtimePom.getArtifactId();
        String camelComponentArtifactId = null;
        if (deps != null && !deps.isEmpty()) {
            Optional<Dependency> artifact = deps.stream()
                    .filter(dep ->

                    "org.apache.camel".equals(dep.getGroupId()) &&
                            ("compile".equals(dep.getScope()) || dep.getScope() == null))
                    .findFirst();
            if (artifact.isPresent()) {
                camelComponentArtifactId = CqCatalog.toCamelComponentArtifactIdBase(artifact.get().getArtifactId());
            }
        }
        final Properties props = runtimePom.getProperties() != null ? runtimePom.getProperties() : new Properties();

        String name = props.getProperty("title");
        if (name == null) {
            name = CqUtils.getNameBase(runtimePom.getName());
        }

        final String version = CqUtils.getVersion(runtimePom);

        return new CamelQuarkusExtension(
                runtimePomXmlPath,
                camelComponentArtifactId,
                (String) props.get("firstVersion"),
                aid,
                name,
                runtimePom.getDescription(),
                props.getProperty("label"),
                version,
                !runtimePomXmlPath.getParent().getParent().getParent().getFileName().toString().endsWith("-jvm"),
                deps == null ? Collections.emptyList() : Collections.unmodifiableList(deps));
    } catch (IOException | XmlPullParserException e) {
        throw new RuntimeException("Could not read " + runtimePomXmlPath, e);
    }
}
 
Example 16
Source File: CreateExtensionMojo.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private TemplateParams getTemplateParams(Model basePom) throws MojoExecutionException {
    final TemplateParams templateParams = new TemplateParams();

    templateParams.artifactId = artifactId;
    templateParams.artifactIdPrefix = artifactIdPrefix;
    templateParams.artifactIdBase = artifactIdBase;
    templateParams.artifactIdBaseCamelCase = toCapCamelCase(templateParams.artifactIdBase);

    if (groupId == null) {
        if (basePom == null) {
            throw new MojoExecutionException(
                    "Please provide the desired groupId for the project by setting groupId parameter");
        }
        templateParams.groupId = getGroupId(basePom);
    } else {
        templateParams.groupId = groupId;
    }

    if (version == null) {
        if (basePom == null) {
            throw new MojoExecutionException(
                    "Please provide the desired version for the project by setting version parameter");
        }
        templateParams.version = getVersion(basePom);
    } else {
        templateParams.version = version;
    }

    templateParams.namePrefix = namePrefix;
    templateParams.nameBase = nameBase;
    templateParams.nameSegmentDelimiter = nameSegmentDelimiter;
    templateParams.assumeManaged = detectAssumeManaged();
    templateParams.quarkusVersion = QUARKUS_VERSION_POM_EXPR;
    templateParams.bomEntryVersion = bomEntryVersion.replace('@', '$');

    if (basePom != null) {
        templateParams.grandParentGroupId = grandParentGroupId != null ? grandParentGroupId : getGroupId(basePom);
        templateParams.grandParentArtifactId = grandParentArtifactId != null ? grandParentArtifactId
                : basePom.getArtifactId();
        templateParams.grandParentVersion = grandParentVersion != null ? grandParentVersion : getVersion(basePom);
        templateParams.grandParentRelativePath = grandParentRelativePath != null ? grandParentRelativePath : "../pom.xml";
    }

    templateParams.javaPackageBase = javaPackageBase != null ? javaPackageBase
            : getJavaPackage(templateParams.groupId, javaPackageInfix, artifactId);
    templateParams.additionalRuntimeDependencies = getAdditionalRuntimeDependencies();
    templateParams.runtimeBomPathSet = runtimeBomPath != null;
    return templateParams;
}
 
Example 17
Source File: MojoUtils.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static String[] readGavFromPom(final InputStream resourceAsStream) throws IOException {
    Model model = readPom(resourceAsStream);
    return new String[] { model.getGroupId(), model.getArtifactId(), model.getVersion() };
}
 
Example 18
Source File: QuarkusJsonPlatformDescriptorResolver.java    From quarkus with Apache License 2.0 4 votes vote down vote up
private static String getArtifactId(Model model) {
    if (model == null) {
        return null;
    }
    return model.getArtifactId();
}
 
Example 19
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public String get( Model model )
{
    return model.getArtifactId();
}
 
Example 20
Source File: LeinRunner.java    From app-runner with MIT License 3 votes vote down vote up
public void start(LineConsumer buildLogHandler, LineConsumer consoleLogHandler, Map<String, String> envVarsForApp, Waiter startupWaiter) throws ProjectCannotStartException {

        runLein(buildLogHandler, envVarsForApp, "do", "test,", "uberjar,", "pom");

        Model model = loadPomModel(new File(projectRoot, "pom.xml"));
        String jarName = model.getArtifactId() + "-" + model.getVersion() + "-standalone.jar";

        CommandLine command = javaCmd.commandLine(envVarsForApp);
        command.addArgument("-jar").addArgument("target" + File.separator + jarName);

        watchDog = ProcessStarter.startDaemon(buildLogHandler, consoleLogHandler, envVarsForApp, command, projectRoot, startupWaiter);
    }