Skip to content

Commit

Permalink
Merge 0706969 into a276551
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentgo committed Feb 25, 2019
2 parents a276551 + 0706969 commit bf5eaf1
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/main/java/pl/project13/maven/git/GitCommitIdMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.google.common.io.Files;
import java.io.OutputStream;


import pl.project13.maven.git.build.BuildServerDataProvider;
import pl.project13.maven.git.log.LoggerBridge;
import pl.project13.maven.git.log.MavenLoggerBridge;
Expand All @@ -63,6 +64,8 @@
*/
@Mojo(name = "revision", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true)
public class GitCommitIdMojo extends AbstractMojo {
private static final String CONTEXT_KEY = GitCommitIdMojo.class.getName() + ".properties";

/**
* The Maven Project.
*/
Expand Down Expand Up @@ -324,7 +327,7 @@ public class GitCommitIdMojo extends AbstractMojo {
*/
@Parameter(defaultValue = "30000")
long nativeGitTimeoutInMs;

/**
* Use branch name from build environment. Set to {@code 'false'} to use JGit/GIT to get current branch name.
* Useful when using the JGitflow maven plugin.
Expand All @@ -333,7 +336,7 @@ public class GitCommitIdMojo extends AbstractMojo {
*/
@Parameter(defaultValue = "true")
boolean useBranchNameFromBuildEnvironment;

/**
* Injected {@link BuildContext} to recognize incremental builds.
*/
Expand Down Expand Up @@ -432,20 +435,31 @@ public void execute() throws MojoExecutionException {
String trimmedPrefix = prefix.trim();
prefixDot = trimmedPrefix.equals("") ? "" : trimmedPrefix + ".";

loadGitData(properties);
loadBuildData(properties);
propertiesReplacer.performReplacement(properties, replacementProperties);
propertiesFilterer.filter(properties, includeOnlyProperties, this.prefixDot);
propertiesFilterer.filterNot(properties, excludeProperties, this.prefixDot);
// check if properties have already been injected
Properties contextProperties = getContextProperties(project);
boolean alreadyInjected = injectAllReactorProjects && contextProperties != null;
if (alreadyInjected) {
log.info("injectAllReactorProjects is enabled and this project already contains properties");
properties = contextProperties;
} else {
loadGitData(properties);
loadBuildData(properties);
propertiesReplacer.performReplacement(properties, replacementProperties);
propertiesFilterer.filter(properties, includeOnlyProperties, this.prefixDot);
propertiesFilterer.filterNot(properties, excludeProperties, this.prefixDot);
}
logProperties();

if (generateGitPropertiesFile) {
maybeGeneratePropertiesFile(properties, project.getBasedir(), generateGitPropertiesFilename);
}
publishPropertiesInto(project);

if (injectAllReactorProjects) {
appendPropertiesToReactorProjects();
if (!alreadyInjected) {
publishPropertiesInto(project);

if (injectAllReactorProjects) {
appendPropertiesToReactorProjects();
}
}
} catch (Exception e) {
handlePluginFailure(e);
Expand Down Expand Up @@ -492,6 +506,7 @@ private void appendPropertiesToReactorProjects() {
log.info("{}] project {}", mavenProject.getName(), mavenProject.getName());

publishPropertiesInto(mavenProject);
mavenProject.setContextValue(CONTEXT_KEY, properties);
}
}

Expand Down Expand Up @@ -609,11 +624,11 @@ private void maybeGeneratePropertiesFile(@Nonnull Properties localProperties, Fi
} catch (final IOException ex) {
throw new RuntimeException("Cannot create custom git properties file: " + gitPropsFile, ex);
}

if (buildContext != null) {
buildContext.refresh(gitPropsFile);
}

} else {
log.info("Properties file [{}] is up-to-date (for module {})...", gitPropsFile.getAbsolutePath(), project.getName());
}
Expand Down Expand Up @@ -678,6 +693,10 @@ private Properties readProperties(@Nonnull File propertiesFile) throws CannotRea
}
}

private Properties getContextProperties(MavenProject project) {
return (Properties) project.getContextValue(CONTEXT_KEY);
}

static class CannotReadFileException extends Exception {
private static final long serialVersionUID = -6290782570018307756L;

Expand Down

0 comments on commit bf5eaf1

Please sign in to comment.