Skip to content
This repository has been archived by the owner. It is now read-only.

Commit eab6f03

Browse files
committed
Merge branch '1.0' into wip/integration
DefaultExternalHooks and WrappedClassFileManager are moved to xsbt.compile.
2 parents 6f87972 + 5ce917d commit eab6f03

File tree

5 files changed

+139
-27
lines changed

5 files changed

+139
-27
lines changed

src/main/contraband-java/xsbti/compile/IncOptions.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,7 @@ public static java.util.Map<String, String> defaultExtra() {
5959
return new java.util.HashMap<String, String>();
6060
}
6161
public static ExternalHooks defaultExternal() {
62-
return new ExternalHooks() {
63-
@Override
64-
public java.util.Optional<Lookup> externalLookup() {
65-
return java.util.Optional.empty();
66-
}
67-
@Override
68-
public java.util.Optional<ClassFileManager> externalClassFileManager() {
69-
return java.util.Optional.empty();
70-
}
71-
};
62+
return new DefaultExternalHooks(java.util.Optional.empty(), java.util.Optional.empty());
7263
}
7364
public static boolean defaultLogRecompileOnMacro() {
7465
return true;

src/main/contraband/incremental.json

+1-10
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,7 @@
230230
" return new java.util.HashMap<String, String>();",
231231
"}",
232232
"public static ExternalHooks defaultExternal() {",
233-
" return new ExternalHooks() {",
234-
" @Override",
235-
" public java.util.Optional<Lookup> externalLookup() {",
236-
" return java.util.Optional.empty();",
237-
" }",
238-
" @Override",
239-
" public java.util.Optional<ClassFileManager> externalClassFileManager() {",
240-
" return java.util.Optional.empty();",
241-
" }",
242-
" };",
233+
" return new DefaultExternalHooks(java.util.Optional.empty(), java.util.Optional.empty());",
243234
"}",
244235
"public static boolean defaultLogRecompileOnMacro() {",
245236
" return true;",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Zinc - The incremental compiler for Scala.
3+
* Copyright 2011 - 2017, Lightbend, Inc.
4+
* Copyright 2008 - 2010, Mark Harrah
5+
* This software is released under the terms written in LICENSE.
6+
*/
7+
8+
package xsbti.compile;
9+
10+
import java.io.File;
11+
import java.util.Optional;
12+
import java.util.Set;
13+
14+
public class DefaultExternalHooks implements ExternalHooks {
15+
private Optional<ExternalHooks.Lookup> lookup = Optional.empty();
16+
private Optional<ClassFileManager> classFileManager = Optional.empty();
17+
18+
public DefaultExternalHooks(Optional<ExternalHooks.Lookup> lookup, Optional<ClassFileManager> classFileManager) {
19+
this.lookup = lookup;
20+
this.classFileManager = classFileManager;
21+
}
22+
23+
@Override
24+
public Optional<Lookup> getExternalLookup() {
25+
return lookup;
26+
}
27+
28+
@Override
29+
public Optional<ClassFileManager> getExternalClassFileManager() {
30+
return classFileManager;
31+
}
32+
33+
@Override
34+
public ExternalHooks withExternalClassFileManager(ClassFileManager externalClassFileManager) {
35+
Optional<ClassFileManager> currentManager = this.getExternalClassFileManager();
36+
Optional<ClassFileManager> mixedManager = currentManager;
37+
if (currentManager.isPresent()) {
38+
Optional<ClassFileManager> external = Optional.of(externalClassFileManager);
39+
mixedManager = Optional.of(WrappedClassFileManager.of(currentManager.get(), external));
40+
}
41+
return new DefaultExternalHooks(this.getExternalLookup(), mixedManager);
42+
}
43+
44+
@Override
45+
public ExternalHooks withExternalLookup(Lookup externalLookup) {
46+
return new DefaultExternalHooks(Optional.of(externalLookup), this.getExternalClassFileManager());
47+
}
48+
}

src/main/java/xsbti/compile/ExternalHooks.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import java.util.Set;
1313

1414
/**
15-
* Define hooks that can be user-defined to modify the behaviour of
15+
* Defines hooks that can be user-defined to modify the behaviour of
1616
* internal components of the incremental compiler.
1717
*/
1818
public interface ExternalHooks {
1919
/**
20-
* Define an interface for a lookup mechanism.
20+
* Defines an interface for a lookup mechanism.
2121
*/
22-
public static interface Lookup {
22+
interface Lookup {
2323

2424
/**
2525
* Used to provide information from external tools into sbt (e.g. IDEs)
@@ -54,17 +54,36 @@ public static interface Lookup {
5454
}
5555

5656
/**
57-
* Return the implementation of a lookup mechanism to be used instead of
57+
* Returns the implementation of a lookup mechanism to be used instead of
5858
* the internal lookup provided by the default implementation.
5959
*/
60-
Optional<Lookup> externalLookup();
60+
Optional<Lookup> getExternalLookup();
6161

6262
/**
63-
* Return the implementation of a {@link ClassFileManager} to be used
63+
* Returns the implementation of a {@link ClassFileManager} to be used
6464
* alongside the internal manager provided by the default implementation.
6565
* <p>
6666
* This class file manager is run after the internal
6767
* {@link ClassFileManager} defined in {@link IncOptions}.
6868
*/
69-
Optional<ClassFileManager> externalClassFileManager();
69+
Optional<ClassFileManager> getExternalClassFileManager();
70+
71+
/**
72+
* Returns an instance of hooks that executes the external passed class file manager.
73+
*
74+
* If several class file manager are passed, they are aggregated and their execution happens
75+
* in the order of invocations of this method.
76+
*
77+
* @return An instance of {@link ExternalHooks} with the aggregated external class file manager.
78+
*/
79+
ExternalHooks withExternalClassFileManager(ClassFileManager externalClassFileManager);
80+
81+
/**
82+
* Returns an instance of hooks with one lookup.
83+
*
84+
* If used several times, only the last lookup instance will be used.
85+
*
86+
* @return An instance of {@link ExternalHooks} with the specified lookup.
87+
*/
88+
ExternalHooks withExternalLookup(Lookup externalLookup);
7089
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Zinc - The incremental compiler for Scala.
3+
* Copyright 2011 - 2017, Lightbend, Inc.
4+
* Copyright 2008 - 2010, Mark Harrah
5+
* This software is released under the terms written in LICENSE.
6+
*/
7+
8+
package xsbti.compile;
9+
10+
import java.io.File;
11+
import java.util.Optional;
12+
13+
/**
14+
* Defines a classfile manager that composes the operation of two classfile manager,
15+
* one being the internal classfile manager (the one used by the compiler) and the
16+
* other one being the external classfile manager (a customizable, build tool-defined
17+
* class file manager to control which class files should be notified/removed/generated
18+
* aside from the ones covered by the internal classfile manager).
19+
*
20+
* @param internal Compiler classfile manager.
21+
* @param external Build tool (or external) classfile manager the complements the internal one.
22+
*/
23+
public class WrappedClassFileManager implements ClassFileManager {
24+
private ClassFileManager internal;
25+
private Optional<ClassFileManager> external;
26+
27+
public static WrappedClassFileManager of(ClassFileManager internal, Optional<ClassFileManager> external) {
28+
return new WrappedClassFileManager(internal, external);
29+
}
30+
31+
protected WrappedClassFileManager(ClassFileManager internal,
32+
Optional<ClassFileManager> external) {
33+
this.internal = internal;
34+
this.external = external;
35+
}
36+
37+
@Override
38+
public void delete(File[] classes) {
39+
// Avoid Java 8 syntax to accommodate Scala 2.10
40+
if (external.isPresent()) {
41+
external.get().delete(classes);
42+
}
43+
internal.delete(classes);
44+
}
45+
46+
@Override
47+
public void complete(boolean success) {
48+
// Avoid Java 8 syntax to accommodate Scala 2.10
49+
if (external.isPresent()) {
50+
external.get().complete(success);
51+
}
52+
internal.complete(success);
53+
}
54+
55+
@Override
56+
public void generated(File[] classes) {
57+
// Avoid Java 8 syntax to accommodate Scala 2.10
58+
if (external.isPresent()) {
59+
external.get().generated(classes);
60+
}
61+
internal.generated(classes);
62+
}
63+
}

0 commit comments

Comments
 (0)