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

The following examples show how to use org.apache.maven.model.Model#getGroupId() . 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: 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 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: ModelUtils.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static String getGroupId(Model model) {
    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 groupId for project model");
}
 
Example 5
Source File: ProjectVersion.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private String groupId(Model model) {
	if (model == null) {
		return "";
	}
	if (StringUtils.hasText(model.getGroupId())) {
		return model.getGroupId();
	}
	if (model.getParent() != null
			&& StringUtils.hasText(model.getParent().getGroupId())) {
		return model.getParent().getGroupId();
	}
	return "";
}
 
Example 6
Source File: PomUpdater.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private String groupId(Model model) {
	if (hasText(model.getGroupId())) {
		return model.getGroupId();
	}
	if (model.getParent() != null) {
		return model.getParent().getGroupId();
	}
	return "";
}
 
Example 7
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 8
Source File: MavenUploadHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String getGroupId(Model model) {
  String groupId = model.getGroupId();
  if (groupId == null && model.getParent() != null) {
    groupId = model.getParent().getGroupId();
  }
  return groupId;
}
 
Example 9
Source File: PomHelper.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the groupId from a raw model, interpolating from the parent if necessary.
 *
 * @param model The model.
 * @return The groupId.
 */
public static String getGroupId( Model model )
{
    String targetGroupId = model.getGroupId();
    if ( targetGroupId == null && model.getParent() != null )
    {
        targetGroupId = model.getParent().getGroupId();
    }
    return targetGroupId;
}
 
Example 10
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 11
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 12
Source File: CreateExtensionMojo.java    From quarkus with Apache License 2.0 4 votes vote down vote up
static String getGroupId(Model basePom) {
    return basePom.getGroupId() != null ? basePom.getGroupId()
            : basePom.getParent() != null && basePom.getParent().getGroupId() != null
                    ? basePom.getParent().getGroupId()
                    : null;
}
 
Example 13
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.getGroupId();
}