Skip to content

Commit

Permalink
Getting ride of guava
Browse files Browse the repository at this point in the history
  • Loading branch information
velo committed Oct 31, 2018
1 parent 2729756 commit 901dfc3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>

<!-- test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.takari.maven.builder.smart;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
Expand All @@ -13,8 +15,6 @@
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.project.MavenProject;

import com.google.common.collect.ImmutableMap;

/**
* Project comparator (factory) that uses project build time to establish build order.
* <p>
Expand All @@ -38,7 +38,7 @@ class ProjectComparator {

public static Comparator<MavenProject> create(MavenSession session) {
final ProjectDependencyGraph dependencyGraph = session.getProjectDependencyGraph();
return create0(DependencyGraph.fromMaven(dependencyGraph), ImmutableMap.of(), p -> id(p));
return create0(DependencyGraph.fromMaven(dependencyGraph), Collections.emptyMap(), p -> id(p));
}

static <K> Comparator<K> create0(final DependencyGraph<K> dependencyGraph,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.project.MavenProject;

import com.google.common.collect.ImmutableSet;

/**
* Reactor build queue manages reactor modules that are waiting for their upstream dependencies
* build to finish.
Expand Down Expand Up @@ -43,8 +41,8 @@ public ReactorBuildQueue(Collection<MavenProject> projects,
}
}

this.rootProjects = ImmutableSet.copyOf(rootProjects);
this.projects = ImmutableSet.copyOf(projects);
this.rootProjects = new HashSet<>(rootProjects);
this.projects = new HashSet<>(projects);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -15,8 +16,6 @@
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.project.MavenProject;

import com.google.common.collect.ImmutableMap;

class ReactorBuildStats {

private long startTime;
Expand All @@ -39,22 +38,22 @@ class ReactorBuildStats {

private ReactorBuildStats(Map<String, AtomicLong> serviceTimes,
Map<String, AtomicLong> bottleneckTimes) {
this.serviceTimes = ImmutableMap.copyOf(serviceTimes);
this.bottleneckTimes = ImmutableMap.copyOf(bottleneckTimes);
this.serviceTimes = new LinkedHashMap<>(serviceTimes);
this.bottleneckTimes = new LinkedHashMap<>(bottleneckTimes);
}

private static String projectGA(MavenProject project) {
return project.getGroupId() + ":" + project.getArtifactId();
}

public static ReactorBuildStats create(Collection<MavenProject> projects) {
ImmutableMap.Builder<String, AtomicLong> serviceTimes = ImmutableMap.builder();
ImmutableMap.Builder<String, AtomicLong> bottleneckTimes = ImmutableMap.builder();
Map<String, AtomicLong> serviceTimes = new LinkedHashMap<>();
Map<String, AtomicLong> bottleneckTimes = new LinkedHashMap<>();
projects.stream().map(project -> projectGA(project)).forEach(key -> {
serviceTimes.put(key, new AtomicLong());
bottleneckTimes.put(key, new AtomicLong());
});
return new ReactorBuildStats(serviceTimes.build(), bottleneckTimes.build());
return new ReactorBuildStats(serviceTimes, bottleneckTimes);
}

public void recordStart() {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/io/takari/maven/builder/smart/SmartBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,21 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Joiner;

/**
* Trivial Maven {@link Builder} implementation. All interesting stuff happens in
* {@link SmartBuilderImpl} .
*/
@Singleton
@Named("smart")
public class SmartBuilder implements Builder {

public static final String PROP_PROFILING = "smartbuilder.profiling";

private final Logger logger = LoggerFactory.getLogger(getClass());

private final LifecycleModuleBuilder moduleBuilder;


@Inject
public SmartBuilder(LifecycleModuleBuilder moduleBuilder) {
this.moduleBuilder = moduleBuilder;
Expand All @@ -55,7 +53,7 @@ public void build(final MavenSession session, final ReactorContext reactorContex

// log overall build info
final int degreeOfConcurrency = session.getRequest().getDegreeOfConcurrency();
logger.info("Task segments : " + Joiner.on(" ").join(taskSegments));
logger.info("Task segments : " + taskSegments);
logger.info("Build maximum degree of concurrency is " + degreeOfConcurrency);
logger.info("Total number of projects is " + graph.getSortedProjects().size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void testPriorityQueueOrder() {
TestProjectDependencyGraph graph = new TestProjectDependencyGraph(a, b, c);
graph.addDependency(b, a);

Comparator<MavenProject> cmp = ProjectComparator.create0(graph, new HashMap<>(), p -> id(p));
Comparator<MavenProject> cmp = ProjectComparator.create0(graph, new LinkedHashMap<>(), p -> id(p));

Queue<MavenProject> queue = new PriorityQueue<>(3, cmp);
queue.add(a);
Expand All @@ -35,7 +35,7 @@ public void testPriorityQueueOrder_historicalServiceTimes() {
TestProjectDependencyGraph graph = new TestProjectDependencyGraph(a, b, c);
graph.addDependency(b, a);

HashMap<String, AtomicLong> serviceTimes = new HashMap<>();
HashMap<String, AtomicLong> serviceTimes = new LinkedHashMap<>();
serviceTimes.put(id(a), new AtomicLong(1L));
serviceTimes.put(id(b), new AtomicLong(1L));
serviceTimes.put(id(c), new AtomicLong(3L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testBuildOrder() throws Exception {
TestProjectDependencyGraph graph = new TestProjectDependencyGraph(a, b, c);
graph.addDependency(b, a);

HashMap<String, AtomicLong> serviceTimes = new HashMap<>();
HashMap<String, AtomicLong> serviceTimes = new LinkedHashMap<>();
serviceTimes.put(id(a), new AtomicLong(1L));
serviceTimes.put(id(b), new AtomicLong(1L));
serviceTimes.put(id(c), new AtomicLong(3L));
Expand Down

0 comments on commit 901dfc3

Please sign in to comment.