Skip to content

Commit

Permalink
ignore by default local-repository, refactor transmission of collecte…
Browse files Browse the repository at this point in the history
…d data

fixes #146
  • Loading branch information
McFoggy committed Jan 28, 2021
1 parent fbcc04c commit 6ccbce8
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 19 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@
<exclude>**/CHANGELOG</exclude>
<exclude>src/quality/**</exclude>
<exclude>src/doc/images/**</exclude>
<exclude>src/it/**/mlr/**</exclude>
<exclude>src/it/resources/**</exclude>
<exclude>src/it/**/invoker.properties</exclude>
<exclude>src/test/resources/**</exclude>
Expand Down
4 changes: 4 additions & 0 deletions src/it/issues/issue-146/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
prebuild.log
build.log
mlr/
target/
25 changes: 25 additions & 0 deletions src/it/issues/issue-146/.mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</extension>
</extensions>
22 changes: 22 additions & 0 deletions src/it/issues/issue-146/.mvn/jgitver.config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration xmlns="http://jgitver.github.io/maven/configuration/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jgitver.github.io/maven/configuration/1.1.0 https://jgitver.github.io/maven/configuration/jgitver-configuration-v1_1_0.xsd">
<strategy>CONFIGURABLE</strategy>
</configuration>
2 changes: 2 additions & 0 deletions src/it/issues/issue-146/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# invoker.mavenOpts = -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
invoker.goals=clean install -Dmaven.repo.local=${basedir}/src/it/issues/issue-146/mlr
55 changes: 55 additions & 0 deletions src/it/issues/issue-146/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] ([email protected])
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.brouillard.oss.it</groupId>
<artifactId>issue-146</artifactId>
<version>0</version>
<packaging>pom</packaging>

<description>Verify MLR is excluded</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo>used version: ${jgitver.used_version}</echo>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
50 changes: 50 additions & 0 deletions src/it/issues/issue-146/prebuild.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def log = new PrintWriter( new File(basedir, "prebuild.log").newWriter("UTF-8"), true )
log.println( "Prebuild started at: " + new Date() + " in: " + basedir )

[
"rm -rf mlr",
"cp -r ../../../../target/local-repo mlr",
"git --version",
"rm -rf .git",
"git init",
"git config user.name nobody",
"git config user.email [email protected]",
"dd if=/dev/urandom of=content bs=512 count=2",
"git add .",
"git commit --message=initial_commit",
"git tag -a 1.0.0 --message=release_1.0.0",
"git status",
"git log --graph --oneline"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0

}

log.println( "Prebuild completed at: " + new Date() )
log.close()
return true
46 changes: 46 additions & 0 deletions src/it/issues/issue-146/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] (matthieu@brouillard.fr)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def log = new PrintWriter( new File(basedir, "verify.log").newWriter("UTF-8"), true )
log.println( "Verify started at: " + new Date() + " in: " + basedir )

[
"chmod -R 755 .git",
"rm -rf .git"
].each{ command ->

def proc = command.execute(null, basedir)
def sout = new StringBuilder(), serr = new StringBuilder()
proc.waitForProcessOutput(sout, serr)

log.println( "cmd: " + command )
log.println( "out:" ) ; log.println( sout.toString().trim() )
log.println( "err:" ) ; log.println( serr.toString().trim() )
log.println( "ret: " + proc.exitValue() )

assert proc.exitValue() == 0

}

def buildLog = new File(basedir, "build.log").readLines()

// Check the version was used by the plugin execution
def versionChanges = buildLog.findAll { it =~ /fr.brouillard.oss.it::issue-146::0 -> 1.0.0/ }
log.println( "versionChanges: " + versionChanges )
assert 0 < versionChanges.size()

log.println( "Verify completed at: " + new Date() )
log.close()
return true
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
import fr.brouillard.oss.jgitver.cfg.ConfigurationLoader;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;

@Component(role = JGitverConfiguration.class, instantiationStrategy = "singleton")
public class JGitverConfigurationComponent implements JGitverConfiguration {
@Requirement private LegacySupport legacySupport = null;

@Requirement private Logger logger = null;

@Requirement private JGitverExecutionInformationProvider executionInformationProvider;

private volatile Configuration configuration;

private List<File> excludedDirectories = new LinkedList<>();
Expand All @@ -44,30 +44,38 @@ public Configuration getConfiguration() throws MavenExecutionException {
if (configuration == null) {
synchronized (this) {
if (configuration == null) {
MavenSession mavenSession = legacySupport.getSession();
final File rootDirectory = mavenSession.getRequest().getMultiModuleProjectDirectory();
final File rootDirectory = executionInformationProvider.getRootDirectory();

logger.debug(
"using " + JGitverUtils.EXTENSION_PREFIX + " on directory: " + rootDirectory);

configuration = ConfigurationLoader.loadFromRoot(rootDirectory, logger);
configuration = new ConfigurationLoader(rootDirectory, logger).load();

initFromRootDirectory(rootDirectory, configuration.exclusions);
excludedDirectories.add(
new File(executionInformationProvider.getLocalRepository().getBasedir()));
excludedDirectories.addAll(
computeExcludedDirectoriesFromConfigurationExclusions(
rootDirectory, configuration.exclusions));
}
}
}

return configuration;
}

private void initFromRootDirectory(File rootDirectory, List<String> exclusions) {
exclusions.stream()
.map(dirName -> new File(rootDirectory, dirName))
.forEach(
dir -> {
excludedDirectories.add(dir);
logger.debug("ignoring directory (& sub dirs): " + dir);
});
private Collection<File> computeExcludedDirectoriesFromConfigurationExclusions(
File rootDirectory, List<String> exclusions) {
return exclusions.stream()
.map(
dirName -> {
File directory = new File(dirName);
if (!directory.isAbsolute()) {
directory = new File(rootDirectory, dirName);
}
logger.debug("ignoring directory (& sub dirs): " + directory);
return directory;
})
.collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.brouillard.oss.jgitver;

import java.io.File;
import java.util.Optional;
import org.apache.maven.artifact.repository.ArtifactRepository;

public interface JGitverExecutionInformationProvider {

ArtifactRepository getLocalRepository();

void setLocalRepository(ArtifactRepository localRepository);

File getRootDirectory();

void setRootDirectory(File rootDirectory);

void setSession(JGitverSession session);

Optional<JGitverSession> session();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2016 Matthieu Brouillard [http://oss.brouillard.fr/jgitver-maven-plugin] ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.brouillard.oss.jgitver;

import java.io.File;
import java.util.Optional;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.codehaus.plexus.component.annotations.Component;

@Component(role = JGitverExecutionInformationProvider.class, instantiationStrategy = "singleton")
public class JGitverExecutionInformationProviderComponent
implements JGitverExecutionInformationProvider {
private ArtifactRepository localRepository;
private File rootDirectory;
private JGitverSession session;

@Override
public ArtifactRepository getLocalRepository() {
return localRepository;
}

@Override
public void setLocalRepository(ArtifactRepository localRepository) {
this.localRepository = localRepository;
}

@Override
public File getRootDirectory() {
return rootDirectory;
}

@Override
public void setRootDirectory(File rootDirectory) {
this.rootDirectory = rootDirectory;
}

@Override
public void setSession(JGitverSession session) {
this.session = session;
}

@Override
public Optional<JGitverSession> session() {
return Optional.ofNullable(session);
}
}
Loading

0 comments on commit 6ccbce8

Please sign in to comment.