-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.0' into wip/integration
DefaultExternalHooks and WrappedClassFileManager are moved to xsbt.compile.
- Loading branch information
Showing
30 changed files
with
500 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
internal/compiler-interface/src/main/java/xsbti/compile/DefaultExternalHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright 2011 - 2017, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* This software is released under the terms written in LICENSE. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
import java.io.File; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
public class DefaultExternalHooks implements ExternalHooks { | ||
private Optional<ExternalHooks.Lookup> lookup = Optional.empty(); | ||
private Optional<ClassFileManager> classFileManager = Optional.empty(); | ||
|
||
public DefaultExternalHooks(Optional<ExternalHooks.Lookup> lookup, Optional<ClassFileManager> classFileManager) { | ||
this.lookup = lookup; | ||
this.classFileManager = classFileManager; | ||
} | ||
|
||
@Override | ||
public Optional<Lookup> getExternalLookup() { | ||
return lookup; | ||
} | ||
|
||
@Override | ||
public Optional<ClassFileManager> getExternalClassFileManager() { | ||
return classFileManager; | ||
} | ||
|
||
@Override | ||
public ExternalHooks withExternalClassFileManager(ClassFileManager externalClassFileManager) { | ||
Optional<ClassFileManager> currentManager = this.getExternalClassFileManager(); | ||
Optional<ClassFileManager> mixedManager = currentManager; | ||
if (currentManager.isPresent()) { | ||
Optional<ClassFileManager> external = Optional.of(externalClassFileManager); | ||
mixedManager = Optional.of(WrappedClassFileManager.of(currentManager.get(), external)); | ||
} | ||
return new DefaultExternalHooks(this.getExternalLookup(), mixedManager); | ||
} | ||
|
||
@Override | ||
public ExternalHooks withExternalLookup(Lookup externalLookup) { | ||
return new DefaultExternalHooks(Optional.of(externalLookup), this.getExternalClassFileManager()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
internal/compiler-interface/src/main/java/xsbti/compile/WrappedClassFileManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Zinc - The incremental compiler for Scala. | ||
* Copyright 2011 - 2017, Lightbend, Inc. | ||
* Copyright 2008 - 2010, Mark Harrah | ||
* This software is released under the terms written in LICENSE. | ||
*/ | ||
|
||
package xsbti.compile; | ||
|
||
import java.io.File; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Defines a classfile manager that composes the operation of two classfile manager, | ||
* one being the internal classfile manager (the one used by the compiler) and the | ||
* other one being the external classfile manager (a customizable, build tool-defined | ||
* class file manager to control which class files should be notified/removed/generated | ||
* aside from the ones covered by the internal classfile manager). | ||
* | ||
* @param internal Compiler classfile manager. | ||
* @param external Build tool (or external) classfile manager the complements the internal one. | ||
*/ | ||
public class WrappedClassFileManager implements ClassFileManager { | ||
private ClassFileManager internal; | ||
private Optional<ClassFileManager> external; | ||
|
||
public static WrappedClassFileManager of(ClassFileManager internal, Optional<ClassFileManager> external) { | ||
return new WrappedClassFileManager(internal, external); | ||
} | ||
|
||
protected WrappedClassFileManager(ClassFileManager internal, | ||
Optional<ClassFileManager> external) { | ||
this.internal = internal; | ||
this.external = external; | ||
} | ||
|
||
@Override | ||
public void delete(File[] classes) { | ||
// Avoid Java 8 syntax to accommodate Scala 2.10 | ||
if (external.isPresent()) { | ||
external.get().delete(classes); | ||
} | ||
internal.delete(classes); | ||
} | ||
|
||
@Override | ||
public void complete(boolean success) { | ||
// Avoid Java 8 syntax to accommodate Scala 2.10 | ||
if (external.isPresent()) { | ||
external.get().complete(success); | ||
} | ||
internal.complete(success); | ||
} | ||
|
||
@Override | ||
public void generated(File[] classes) { | ||
// Avoid Java 8 syntax to accommodate Scala 2.10 | ||
if (external.isPresent()) { | ||
external.get().generated(classes); | ||
} | ||
internal.generated(classes); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
internal/zinc-core/src/main/java/xsbti/compile/AnalysisContents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package xsbti.compile; | ||
|
||
import sbt.internal.inc.ConcreteAnalysisContents; | ||
|
||
/** | ||
* Defines an analysis file that contains information about every incremental compile. | ||
* | ||
* This information can be persisted using an {@link AnalysisStore}. | ||
*/ | ||
public interface AnalysisContents { | ||
/** | ||
* Returns an instance of {@link AnalysisContents} backed up by the default implementation. | ||
* | ||
* @param analysis An instance of {@link CompileAnalysis}. | ||
* @param setup An instance of {@link MiniSetup}. | ||
* @return An instance of {@link AnalysisContents}. | ||
*/ | ||
static AnalysisContents create(CompileAnalysis analysis, MiniSetup setup) { | ||
return new ConcreteAnalysisContents(analysis, setup); | ||
} | ||
|
||
/** | ||
* @return An instance of {@link CompileAnalysis}. | ||
*/ | ||
CompileAnalysis getAnalysis(); | ||
|
||
/** | ||
* @return An instance of {@link MiniSetup}. | ||
*/ | ||
MiniSetup getMiniSetup(); | ||
} |
65 changes: 65 additions & 0 deletions
65
internal/zinc-core/src/main/java/xsbti/compile/AnalysisStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package xsbti.compile; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Defines a store interface that provides analysis read and write capabilities to users. | ||
* | ||
* The store is a backend-independent interface that allows implementors to decide how | ||
* the analysis stores are read and written before or after every incremental compile. | ||
* | ||
* The implementations of {@link AnalysisStore} live in interfaces extending this one. | ||
*/ | ||
public interface AnalysisStore { | ||
/** | ||
* Returns an analysis store whose last contents are kept in-memory. | ||
* | ||
* There will be only one memory reference to an analysis files. Previous contents | ||
* will be discarded as {@link AnalysisStore#set(AnalysisContents)} or | ||
* {@link AnalysisStore#get()} is used. | ||
* | ||
* @param analysisStore The underlying analysis store that knows how to read/write contents. | ||
* @return An instance of a cached {@link AnalysisStore}. | ||
*/ | ||
static AnalysisStore getCachedStore(AnalysisStore analysisStore) { | ||
return sbt.internal.inc.AnalysisStore.cached(analysisStore); | ||
} | ||
|
||
/** | ||
* Returns a synchronized analysis store that is thread-safe. | ||
* | ||
* Thread-safety is achieved by synchronizing in the object. | ||
* | ||
* @param analysisStore The underlying analysis store that knows how to read/write contents. | ||
* @return An instance of a thread-safe {@link AnalysisStore}. | ||
*/ | ||
static AnalysisStore getThreadSafeStore(AnalysisStore analysisStore) { | ||
return sbt.internal.inc.AnalysisStore.sync(analysisStore); | ||
} | ||
|
||
/** | ||
* Gets an {@link AnalysisContents} from the underlying store. | ||
* | ||
* The contents of the analysis file are necessary for subsequent incremental compiles | ||
* given that the analysis files contains information about the previous incremental | ||
* compile and lets the incremental compiler decide what needs or needs not to be recompiled. | ||
* | ||
* This method should be called before every incremental compile. | ||
* | ||
* @return An instance of an optional {@link AnalysisContents}, depending on whether if exists or not. | ||
*/ | ||
Optional<AnalysisContents> get(); | ||
|
||
/** | ||
* Sets an {@link AnalysisContents} to the underlying store. | ||
* | ||
* The contents of the analysis file are necessary for subsequent incremental compiles | ||
* given that the analysis files contains information about the previous incremental | ||
* compile and lets the incremental compiler decide what needs or needs not to be recompiled. | ||
* | ||
* This method is called after every incremental compile. | ||
* | ||
* @return An instance of {@link AnalysisContents}. | ||
*/ | ||
void set(AnalysisContents analysisContents); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.