Skip to content

Commit

Permalink
don't persist/read build timing
Browse files Browse the repository at this point in the history
proved to be less useful in real life, where incremental build,
changing build goals and --projects make previous build timing
virtually useless in predicting current build timing.

Signed-off-by: Igor Fedorenko <ifedorenko@salesforce.com>
  • Loading branch information
ifedorenko committed Mar 4, 2017
1 parent 122c307 commit 3f813eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 79 deletions.
59 changes: 9 additions & 50 deletions src/main/java/io/takari/maven/builder/smart/ProjectComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import io.takari.maven.builder.smart.BuildMetrics.Timer;

import java.io.*;
import java.util.*;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.maven.execution.MavenSession;
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 @@ -32,8 +38,7 @@ class ProjectComparator {

public static Comparator<MavenProject> create(MavenSession session) {
final ProjectDependencyGraph dependencyGraph = session.getProjectDependencyGraph();
final Map<String, Long> historicalServiceTimes = readServiceTimes(session);
return create(dependencyGraph, historicalServiceTimes);
return create(dependencyGraph, ImmutableMap.of());
}

// public for unit testing
Expand Down Expand Up @@ -88,15 +93,6 @@ private static long average(Collection<Long> values) {
return average;
}

private static long parseServiceTime(String string) {
try {
long value = Long.parseLong(string);
return value > 0 ? value : 0;
} catch (NumberFormatException e) {
return 0;
}
}

private static Long getServiceTime(Map<String, Long> serviceTimes, MavenProject project,
long defaultServiceTime) {
Long serviceTime = serviceTimes.get(id(project));
Expand Down Expand Up @@ -132,28 +128,6 @@ private static long calculateWeights(ProjectDependencyGraph dependencyGraph,
return weight;
}

private static Map<String, Long> readServiceTimes(MavenSession session) {
Map<String, Long> result = new HashMap<>();
final File timingFile = getTimingFile(session);
Properties properties = new Properties();
if (timingFile != null) {
try (InputStream is = new FileInputStream(timingFile)) {
properties.load(is);
} catch (IOException e) {
// that's ok
}
for (String id : properties.stringPropertyNames()) {
result.put(id, parseServiceTime(properties.getProperty(id)));
}
}
return result;
}

private static File getTimingFile(MavenSession session) {
File mvndir = new File(session.getRequest().getMultiModuleProjectDirectory(), ".mvn");
return mvndir.isDirectory() ? new File(mvndir, "timing.properties") : null;
}

public static String id(MavenProject project) {
StringBuilder sb = new StringBuilder();
sb.append(project.getGroupId());
Expand All @@ -164,21 +138,6 @@ public static String id(MavenProject project) {
return sb.toString();
}

public static void writeServiceTimes(MavenSession session, ProjectsBuildMetrics metrics)
throws IOException {
final File timingFile = getTimingFile(session);
if (timingFile != null && timingFile.isFile()) {
Properties properties = new Properties();
for (MavenProject project : metrics.getProjects()) {
long serviceTime = metrics.getBuildMetrics(project).getMetricMillis(Timer.SERVICETIME_MS);
properties.put(id(project), Long.toString(serviceTime));
}
try (OutputStream os = new FileOutputStream(timingFile)) {
properties.store(os, null);
}
}
}

public static Comparator<MavenProject> create(ProjectDependencyGraph projectDependencyGraph,
ProjectsBuildMetrics projectsBuildMetrics) {
Map<String, Long> serviceTimes = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* the License.
*/

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -177,11 +176,6 @@ public void build() throws ExecutionException, InterruptedException {

final long buildStopwatchEnd = System.currentTimeMillis();

try {
ProjectComparator.writeServiceTimes(rootSession, projectsBuildMetrics);
} catch (IOException e) {
throw new ExecutionException(e);
}

if (isProfiling()) {
report(buildStopwatchEnd - buildStopwatch);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package io.takari.maven.builder.smart.its;

import static io.takari.maven.testing.TestResources.assertFilesNotPresent;
import static io.takari.maven.testing.TestResources.assertFilesPresent;

import java.io.File;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.takari.maven.testing.TestProperties;
import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenExecution;
Expand All @@ -9,17 +18,6 @@
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;

import static io.takari.maven.testing.TestResources.*;

import java.io.File;
import java.io.FileOutputStream;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.3.1", "3.3.9"})
public class SmartBuilderIntegrationTest {
Expand All @@ -39,9 +37,6 @@ public SmartBuilderIntegrationTest(MavenRuntimeBuilder runtimeBuilder) throws Ex
@Test
public void testBasic() throws Exception {
File basedir = resources.getBasedir("basic-it");
File timingFile = new File(basedir, ".mvn/timing.properties");

assertEquals("timingFile.exists", false, timingFile.exists()); // sanity check

MavenExecution execution = verifier.forProject(basedir) //
.withCliOptions("--builder", "smart") //
Expand All @@ -51,15 +46,6 @@ public void testBasic() throws Exception {

MavenExecutionResult result = execution.execute("package");
result.assertErrorFreeLog();
assertEquals("timingFile.exists", false, timingFile.isFile());

new FileOutputStream(timingFile).close();

result = execution.execute("package");
result.assertErrorFreeLog();

assertEquals("timingFile.exists", true, timingFile.isFile());
assertTrue("timingFile.length > 0", timingFile.length() > 0);
}

@Test
Expand Down

0 comments on commit 3f813eb

Please sign in to comment.