Skip to content

Commit

Permalink
Get rid of Guava from compile/runtime scope (ban it to test scope) (#117
Browse files Browse the repository at this point in the history
)

Changes:
* guice changed to "vanilla"
* guava banned to test scope
* sources has been updated, some older java constructs reworked
  • Loading branch information
cstamas authored Nov 12, 2023
1 parent 9fb2ebf commit 9b0f8a3
Show file tree
Hide file tree
Showing 29 changed files with 261 additions and 265 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
<takari.javaSourceVersion>8</takari.javaSourceVersion>
<mavenVersion>3.8.6</mavenVersion>
<sisuVersion>0.3.5</sisuVersion>
<sisuGuiceVersion>4.2.0</sisuGuiceVersion>
<aetherVersion>1.8.2</aetherVersion>
<incrementalbuild.version>1.0.0</incrementalbuild.version>
<guava.version>31.1-jre</guava.version>
<guava.version>32.1.2-jre</guava.version>
<mavenPluginPluginVersion>3.6.4</mavenPluginPluginVersion>
<m2eWorkspaceVersion>0.4.0</m2eWorkspaceVersion>
<plexusVersion>3.5.1</plexusVersion>
Expand Down
18 changes: 9 additions & 9 deletions takari-lifecycle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
<classifier>no_aop</classifier>
<version>${sisuGuiceVersion}</version>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -163,11 +162,6 @@
<artifactId>compiler</artifactId>
<version>0.9.10</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- JAR -->
<dependency>
<groupId>io.takari</groupId>
Expand Down Expand Up @@ -211,6 +205,12 @@
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
*/
package io.takari.maven.plugins.compile;

import com.google.common.base.Charsets;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import io.takari.incrementalbuild.Incremental;
import io.takari.incrementalbuild.Incremental.Configuration;
import io.takari.incrementalbuild.ResourceMetadata;
Expand All @@ -35,13 +27,16 @@
import org.slf4j.LoggerFactory;

import javax.tools.JavaFileObject.Kind;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

Expand Down Expand Up @@ -97,14 +92,14 @@ public static enum Sourcepath {
/**
* The -target argument for the Java compiler. The default depends on the value of {@code source} as defined in javac documentation.
*
* @see http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html
* @see <a href="https://docs.oracle.com/javase/6/docs/technotes/tools/solaris/javac.html>javac</a>
*/
@Parameter(property = "maven.compiler.target")
private String target;

/**
* The --release argument for the Java compiler.
* @see https://docs.oracle.com/javase/9/tools/javac.htm#JSWOR627
* @see <a href="https://docs.oracle.com/javase/9/tools/javac.htm#JSWOR627">release argument for compiler</a>
*/
@Parameter(property = "maven.compiler.release")
private String release;
Expand All @@ -116,13 +111,13 @@ public static enum Sourcepath {
protected String compilerId;

/**
* Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if {@link #fork} is set to <code>true</code>.
* Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if {{@code forked-javac} is used.
*/
@Parameter(property = "maven.compiler.meminitial")
private String meminitial;

/**
* Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if {@link #fork} is set to <code>true</code>.
* Sets the maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if {{@code forked-javac} is used..
*/
@Parameter(property = "maven.compiler.maxmem")
private String maxmem;
Expand Down Expand Up @@ -228,7 +223,7 @@ public static enum Sourcepath {
* The main usecase is {@code proc:only} annotation processing bound to generate-sources build phase. During {@code mvn clean generate-sources} execution, the reactor dependencies classes are not
* available and referenced types can only be resolved from java sources.
*
* @see http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javac.html#BHCJJJAJ
* @see <a href="http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javac.html#BHCJJJAJ">documentation</a>
* @since 1.12
*/
@Parameter
Expand Down Expand Up @@ -369,7 +364,7 @@ protected Set<File> getDirectDependencies() {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

Stopwatch stopwatch = Stopwatch.createStarted();
long started = System.currentTimeMillis();
context.setFailOnError(failOnError);
if (isSkip()) {
log.info("Skipping compilation");
Expand Down Expand Up @@ -437,7 +432,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (sourcesChanged || classpathChanged || sourcepathChanged || processorpathChanged) {
log.info("Compiling {} sources to {}", sources.size(), getOutputDirectory());
int compiled = compiler.compile();
log.info("Compiled {} out of {} sources ({} ms)", compiled, sources.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
log.info("Compiled {} out of {} sources ({} ms)", compiled, sources.size(), System.currentTimeMillis() - started);
} else {
compiler.skipCompile();
log.info("Skipped compilation, all {} classes are up to date", sources.size());
Expand Down Expand Up @@ -483,7 +478,10 @@ private List<File> getSourcepath(Proc proc) throws MojoExecutionException {
}

Set<File> sourcepath = new LinkedHashSet<>();
for (String sourceRoot : Iterables.concat(getSourceRoots(), getMainSourceRoots())) {
for (String sourceRoot : getSourceRoots()) {
addIfExists(sourcepath, sourceRoot);
}
for (String sourceRoot : getMainSourceRoots()) {
addIfExists(sourcepath, sourceRoot);
}
List<Artifact> unsupportedDependencies = new ArrayList<>();
Expand Down Expand Up @@ -514,7 +512,7 @@ private List<File> getSourcepath(Proc proc) throws MojoExecutionException {
log.debug("Compile sourcepath: {} entries{}", sourcepath.size(), msg.toString());
}

return ImmutableList.copyOf(sourcepath);
return Collections.unmodifiableList(new ArrayList<>(sourcepath));
}

private static void addIfExists(Set<File> sourcepath, String path) {
Expand All @@ -538,22 +536,29 @@ private Collection<String> getSourceRoots(MavenProject other, Artifact artifact)
private Proc getEffectiveProc(List<File> classpath, List<File> processorpath) {
Proc proc = this.proc;
if (proc == null) {
Multimap<File, String> processors = TreeMultimap.create();
Map<File, List<String>> processors = new TreeMap<>();
for (File jar : processorpath != null ? processorpath : classpath) {
if (jar.isFile()) {
try (ZipFile zip = new ZipFile(jar)) {
ZipEntry entry = zip.getEntry("META-INF/services/javax.annotation.processing.Processor");
if (entry != null) {
try (Reader r = new InputStreamReader(zip.getInputStream(entry), Charsets.UTF_8)) {
processors.putAll(jar, CharStreams.readLines(r));
try (BufferedReader r = new BufferedReader(new InputStreamReader(zip.getInputStream(entry), StandardCharsets.UTF_8))) {
List<String> lines = r.lines().collect(Collectors.toList());
if (!lines.isEmpty()) {
processors.computeIfAbsent( jar, k -> new ArrayList<>() ).addAll(lines);
}
}
}
} catch (IOException e) {
// ignore, compiler won't be able to use this jar either
}
} else if (jar.isDirectory()) {
try {
processors.putAll(jar, Files.readLines(new File(jar, "META-INF/services/javax.annotation.processing.Processor"), Charsets.UTF_8));
List<String> lines = Files.readAllLines(
new File( jar, "META-INF/services/javax.annotation.processing.Processor" ).toPath(), StandardCharsets.UTF_8);
if (!lines.isEmpty()) {
processors.computeIfAbsent( jar, k -> new ArrayList<>() ).addAll(lines);
}
} catch (IOException e) {
// ignore, compiler won't be able to use this jar either
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import org.eclipse.aether.util.filter.AndDependencyFilter;
import org.eclipse.aether.util.filter.ScopeDependencyFilter;

import com.google.common.base.Strings;

@Named
class ProcessorpathResolver {

Expand All @@ -61,7 +59,8 @@ public List<File> resolve(RepositorySystemSession session, MavenProject project,

Map<String, Artifact> artifacts = project.getArtifactMap();
for (Dependency dependency : dependencies) {
if (Strings.isNullOrEmpty(dependency.getVersion())) {
String version = dependency.getVersion();
if (version == null || version.isEmpty()) {
Artifact artifact = artifacts.get(ArtifactUtils.versionlessKey(dependency.getGroupId(), dependency.getArtifactId()));
if (artifact != null) {
dependency = dependency.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;
import javax.inject.Named;
Expand All @@ -27,8 +26,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Stopwatch;

@Named
@MojoExecutionScoped
public class ProjectClasspathDigester {
Expand Down Expand Up @@ -63,7 +60,7 @@ public boolean digestProcessorpath(List<File> dependencies) throws IOException {
}

private boolean digest(String key, List<File> dependencies) {
Stopwatch stopwatch = Stopwatch.createStarted();
long started = System.currentTimeMillis();

Map<File, ArtifactFile> previousArtifacts = getPreviousDependencies(key);
LinkedHashMap<File, ArtifactFile> digest = new LinkedHashMap<>();
Expand Down Expand Up @@ -103,7 +100,7 @@ private boolean digest(String key, List<File> dependencies) {

context.setAttribute(key, new ArrayList<>(digest.values()));

log.debug("Analyzed {} classpath dependencies ({} ms)", dependencies.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
log.debug("Analyzed {} classpath dependencies ({} ms)", dependencies != null ? dependencies.size() : 0, System.currentTimeMillis() - started);

return changed;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.takari.maven.plugins.compile;

import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.inject.Inject;
Expand All @@ -11,8 +13,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;

import com.google.common.collect.ImmutableMap;

@Named
@SessionScoped
class ReactorProjects {
Expand All @@ -25,7 +25,7 @@ public ReactorProjects(MavenSession session) {
for (MavenProject project : session.getProjects()) {
projects.put(key(project.getGroupId(), project.getArtifactId(), project.getVersion()), project);
}
this.projects = ImmutableMap.copyOf(projects);
this.projects = Collections.unmodifiableMap(new LinkedHashMap<>(projects));
}

public MavenProject get(Artifact artifact) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
package io.takari.maven.plugins.compile.javac;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import io.takari.incrementalbuild.Resource;
import io.takari.incrementalbuild.ResourceMetadata;
import io.takari.incrementalbuild.ResourceStatus;
Expand All @@ -24,7 +22,14 @@

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public abstract class AbstractCompilerJavac extends AbstractCompiler {

Expand All @@ -42,7 +47,7 @@ public abstract class AbstractCompilerJavac extends AbstractCompiler {

private final ProjectClasspathDigester digester;

private final List<ResourceMetadata<File>> sources = new ArrayList<ResourceMetadata<File>>();
private final List<ResourceMetadata<File>> sources = new ArrayList<>();

private String classpath;
private String sourcepath = "";
Expand All @@ -54,7 +59,7 @@ protected AbstractCompilerJavac(CompilerBuildContext context, ProjectClasspathDi
}

protected List<String> getCompilerOptions() {
List<String> options = new ArrayList<String>();
List<String> options = new ArrayList<>();

// output directory
options.add("-d");
Expand Down Expand Up @@ -146,7 +151,7 @@ protected List<String> getCompilerOptions() {
}
keywords.append(keyword.name());
}
options.add("-g:" + keywords.toString());
options.add("-g:" + keywords);
}

if (isShowWarnings()) {
Expand All @@ -171,7 +176,7 @@ public boolean setClasspath(List<File> dependencies, File mainClasses, Set<File>
for (File element : classpath) {
msg.append("\n   ").append(element);
}
log.debug("Compile classpath: {} entries{}", classpath.size(), msg.toString());
log.debug("Compile classpath: {} entries{}", classpath.size(), msg);
}

StringBuilder cp = new StringBuilder();
Expand Down Expand Up @@ -203,8 +208,8 @@ public boolean setSourcepath(List<File> dependencies, Set<File> sourceRoots) thr
public boolean setSources(List<ResourceMetadata<File>> sources) {
this.sources.addAll(sources);

List<ResourceMetadata<File>> modifiedSources = new ArrayList<ResourceMetadata<File>>();
List<ResourceMetadata<File>> inputs = new ArrayList<ResourceMetadata<File>>();
List<ResourceMetadata<File>> modifiedSources = new ArrayList<>();
List<ResourceMetadata<File>> inputs = new ArrayList<>();
for (ResourceMetadata<File> input : sources) {
inputs.add(input);
if (input.getStatus() != ResourceStatus.UNMODIFIED) {
Expand Down Expand Up @@ -251,11 +256,11 @@ public boolean setProcessorpath(List<File> processorpath) throws IOException {
for (File element : processorpath) {
msg.append("\n   ").append(element);
}
log.debug("Processorpath: {} entries{}", processorpath.size(), msg.toString());
log.debug("Processorpath: {} entries{}", processorpath.size(), msg);
}
this.processorpath = Joiner.on(File.pathSeparatorChar).join(processorpath);
this.processorpath = processorpath.stream().map(File::toString).collect(Collectors.joining(File.pathSeparator));
}
return digester.digestProcessorpath(processorpath != null ? processorpath : ImmutableList.<File>of());
return digester.digestProcessorpath(processorpath != null ? processorpath : Collections.emptyList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import java.io.File;
import java.io.Serializable;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import com.google.common.collect.ImmutableSet;

/**
* State necessary to implement all-or-nothing annotation processing behaviour.
*/
Expand All @@ -23,9 +23,9 @@ class AnnotationProcessingState implements Serializable {
public final Set<File> writtenOutputs;

public AnnotationProcessingState(Set<File> processedSources, ReferenceCollection referencedTypes, Set<File> writtenOutputs) {
this.processedSources = ImmutableSet.copyOf(processedSources);
this.processedSources = Collections.unmodifiableSet(new LinkedHashSet<>(processedSources));
this.referencedTypes = referencedTypes;
this.writtenOutputs = ImmutableSet.copyOf(writtenOutputs);
this.writtenOutputs = Collections.unmodifiableSet(new LinkedHashSet<>(writtenOutputs));
}

}
Loading

0 comments on commit 9b0f8a3

Please sign in to comment.