Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fractal
fractal
Commits
6b8e7680
Commit
6b8e7680
authored
Jan 02, 2018
by
Lionel Seinturier
Browse files
Remove CompilationRound.
parent
754bedac
Changes
5
Hide whitespace changes
Inline
Side-by-side
juliac/core/src/main/java/org/objectweb/fractal/juliac/CompilationRound.java
deleted
100644 → 0
View file @
754bedac
/***
* Juliac
* Copyright (C) 2007-2017 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: fractal@ow2.org
*
* Author: Lionel Seinturier
*/
package
org.objectweb.fractal.juliac
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.logging.Logger
;
import
org.objectweb.fractal.juliac.module.CompileSupportItf
;
/**
* This class holds data about the input files which are compiled by Juliac.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
*/
public
class
CompilationRound
{
public
CompilationRound
(
Juliac
jconf
)
{
this
.
jconf
=
jconf
;
}
public
void
addInput
(
List
<
SourceFile
>
sfs
)
{
inputFiles
.
addAll
(
sfs
);
}
/**
* Add a generated file.
*
* @param sf the source file containing the generated code
* @param sourceType the source type from which the code has been generated
*/
public
void
addGenerated
(
SourceFile
sf
,
Object
sourceType
)
{
generatedFiles
.
add
(
sf
);
String
qname
=
sf
.
getQname
();
sourceTypes
.
put
(
qname
,
sourceType
);
Logger
logger
=
jconf
.
getLogger
();
logger
.
info
(
sf
.
getQname
());
}
/**
* Return <code>true</code> if the specified qualified name corresponds to
* a generated type name.
*
* @since 2.7
*/
public
boolean
contains
(
String
qname
)
{
return
sourceTypes
.
containsKey
(
qname
);
}
/**
* Return the source type corresponding to the specified qualified name.
*
* @since 2.7
*/
public
Object
getSourceType
(
String
qname
)
{
return
sourceTypes
.
get
(
qname
);
}
/**
* Return <code>true</code> if the specified file has already been generated
* in this compilation round.
*/
public
boolean
contains
(
SourceFile
sf
)
{
boolean
b
=
generatedFiles
.
contains
(
sf
);
return
b
;
}
/**
* Compile the input source and generated files.
*/
public
void
compile
(
CompileSupportItf
compiler
)
throws
IOException
{
if
(
inputFiles
.
size
()
+
generatedFiles
.
size
()
>
0
)
{
/*
* Only compiles if there are some files to compile. In addition to
* saving time, this checks is needed by the JDK6 compiler that
* reports an error if the list of files to compile is empty. Note
* however that this is not the case with JDT.
*/
List
<
SourceFile
>
sfs
=
new
ArrayList
<>();
sfs
.
addAll
(
inputFiles
);
sfs
.
addAll
(
generatedFiles
);
File
classDir
=
jconf
.
getClassDir
();
outputFiles
=
compiler
.
compile
(
sfs
,
classDir
);
}
}
public
List
<
SourceFile
>
getInputFiles
()
{
return
inputFiles
;
}
public
List
<
SourceFile
>
getGeneratedFiles
()
{
return
generatedFiles
;
}
public
List
<
String
>
getOutputFileNames
()
{
return
outputFiles
;
}
public
File
getClassDir
()
throws
IOException
{
return
jconf
.
getClassDir
();
}
// --------------------------------------------------------------------
// Data
// --------------------------------------------------------------------
private
Juliac
jconf
;
/** The source files which are given as input to Juliac. */
private
List
<
SourceFile
>
inputFiles
=
new
ArrayList
<>();
/** The source files which are generated by Juliac. */
private
List
<
SourceFile
>
generatedFiles
=
new
ArrayList
<>();
/**
* This map contains the source types that triggered the generation of
* files. The map is indexed by qualified names of generated files.
*
* @since 2.7
*/
private
Map
<
String
,
Object
>
sourceTypes
=
new
HashMap
<>();
/** The names of .class files ouputted by the compilation process. */
private
List
<
String
>
outputFiles
=
new
ArrayList
<>();
}
juliac/core/src/main/java/org/objectweb/fractal/juliac/Juliac.java
View file @
6b8e7680
...
...
@@ -369,9 +369,8 @@ public class Juliac {
URI
uri
=
generateSourceCodeOverride
(
scg
);
CompilationRound
round
=
getCompilationRound
();
Object
sourceType
=
scg
.
getSourceType
();
round
.
addGenerated
(
addGenerated
(
new
SourceFileDir
(
uri
,
targetClassName
,
"java"
),
sourceType
);
}
...
...
@@ -428,11 +427,9 @@ public class Juliac {
*/
public
boolean
hasBeenGenerated
(
String
name
)
{
CompilationRound
round
=
getCompilationRound
();
// Check whether the type has been generated by Juliac
SourceFile
igf
=
new
SourceFileDir
(
null
,
name
,
"java"
);
if
(
round
.
contains
(
igf
)
)
{
if
(
contains
(
igf
)
)
{
return
true
;
}
...
...
@@ -499,15 +496,13 @@ public class Juliac {
*/
public
void
build
()
throws
IOException
{
Logger
logger
=
getLogger
();
CompilationRound
round
=
getCompilationRound
();
/*
* Compile input and generated source files.
*/
Logger
logger
=
getLogger
();
logger
.
info
(
"Compiling..."
);
List
<
SourceFile
>
inputFiles
=
round
.
getInputFiles
();
List
<
SourceFile
>
generatedFiles
=
round
.
getGeneratedFiles
();
List
<
SourceFile
>
inputFiles
=
getInputFiles
();
List
<
SourceFile
>
generatedFiles
=
getGeneratedFiles
();
if
(
inputFiles
.
size
()!=
0
||
generatedFiles
.
size
()!=
0
)
{
// Set the compilation log level
...
...
@@ -518,8 +513,9 @@ public class Juliac {
}
// Compile
CompileSupportItf
compiler
=
lookupUnique
(
CompileSupportItf
.
class
);
round
.
compile
(
compiler
);
CompileSupportItf
compiler
=
lookupUnique
(
CompileSupportItf
.
class
);
compile
(
compiler
);
// Reset the compilation log level
if
(
compilationWarnings
)
{
...
...
@@ -536,9 +532,9 @@ public class Juliac {
final
int
total
=
inputFiles
.
size
()
+
generatedFiles
.
size
();
final
String
msg
=
total
+
" file(s) compiled to "
+
round
.
getClassDir
().
getAbsolutePath
();
getClassDir
().
getAbsolutePath
();
logger
.
info
(
msg
);
}
}
}
/**
...
...
@@ -548,7 +544,7 @@ public class Juliac {
*
* @since 2.2.4
*/
public
void
buildQuiet
()
throws
IOException
{
public
void
buildQuiet
()
{
/*
* Copy/paste of the #compile() method without log invocations. Getting
...
...
@@ -559,13 +555,104 @@ public class Juliac {
* current usage patterns of Juliac (but who knows in the future ;-)
*/
CompilationRound
round
=
getCompilationRound
();
// Compile input and generated source files
CompileSupportItf
compiler
=
lookupUnique
(
CompileSupportItf
.
class
);
round
.
compile
(
compiler
);
compile
(
compiler
);
}
/**
* Add input files.
*
* @param sfs the input files
* @since 2.7
*/
private
void
addInput
(
List
<
SourceFile
>
sfs
)
{
inputFiles
.
addAll
(
sfs
);
}
/**
* Add a generated file.
*
* @param sf the source file containing the generated code
* @param sourceType the source type from which the code has been generated
* @since 2.7
*/
public
void
addGenerated
(
SourceFile
sf
,
Object
sourceType
)
{
generatedFiles
.
add
(
sf
);
String
qname
=
sf
.
getQname
();
sourceTypes
.
put
(
qname
,
sourceType
);
Logger
logger
=
getLogger
();
logger
.
info
(
sf
.
getQname
());
}
/**
* Return <code>true</code> if the specified qualified name
* corresponds to a generated type name.
*
* @since 2.7
*/
public
boolean
contains
(
String
qname
)
{
return
sourceTypes
.
containsKey
(
qname
);
}
/**
* Return the source type corresponding to the specified qualified
* name.
*
* @since 2.7
*/
public
Object
getSourceType
(
String
qname
)
{
return
sourceTypes
.
get
(
qname
);
}
/**
* Return <code>true</code> if the specified file has already been
* generated in this compilation round.
*
* @param sf the generated file
* @since 2.7
*/
private
boolean
contains
(
SourceFile
sf
)
{
boolean
b
=
generatedFiles
.
contains
(
sf
);
return
b
;
}
/**
* Compile the input source and generated files.
*
* @since 2.7
*/
private
void
compile
(
CompileSupportItf
compiler
)
{
// Only compiles if there are some files to compile
if
(
inputFiles
.
size
()
+
generatedFiles
.
size
()
>
0
)
{
List
<
SourceFile
>
sfs
=
new
ArrayList
<>();
sfs
.
addAll
(
inputFiles
);
sfs
.
addAll
(
generatedFiles
);
}
// Reset the lists of input and generated files
inputFiles
=
new
ArrayList
<>();
generatedFiles
=
new
ArrayList
<>();
}
private
List
<
SourceFile
>
getInputFiles
()
{
return
inputFiles
;
}
private
List
<
SourceFile
>
getGeneratedFiles
()
{
return
generatedFiles
;
}
/** The source files which are given as input to Juliac. */
private
List
<
SourceFile
>
inputFiles
=
new
ArrayList
<>();
/** The source files which are generated by Juliac. */
private
List
<
SourceFile
>
generatedFiles
=
new
ArrayList
<>();
/**
* The source types that triggered the generation of files. The map
* is indexed by qualified names of generated files.
*
* @since 2.7
*/
private
Map
<
String
,
Object
>
sourceTypes
=
new
HashMap
<>();
// ----------------------------------------------------------------------
// Class loading
...
...
@@ -639,6 +726,7 @@ public class Juliac {
put
(
"void"
,
void
.
class
);
}};
// ----------------------------------------------------------------------
// Modules and services management
// ----------------------------------------------------------------------
...
...
@@ -897,7 +985,6 @@ public class Juliac {
Charset
.
defaultCharset
().
displayName
();
private
ClassLoader
classLoader
;
private
CompilationRound
round
;
/**
* The default logger.
...
...
@@ -989,12 +1076,12 @@ public class Juliac {
}
/**
* Add the specified location to the list of locations. A location
denotes
* either an absolute path or a path relative to
{@link #baseDir}, for a
* directory or a jar file. All source files
contained in the specified
*
location are registered with the CompilationRound API
for being
* compiled when requested (see {@link #build()}) or processed by
the
* juliac-spoon module (see SpoonSupportImpl.)
* Add the specified location to the list of locations. A location
*
denotes
either an absolute path or a path relative to
*
{@link #baseDir}, for a
directory or a jar file. All source files
*
contained in the specified location are registered
for being
* compiled when requested (see {@link #build()}) or processed by
*
the
juliac-spoon module (see SpoonSupportImpl.)
*
* @param src the location to add
* @throws IOException
...
...
@@ -1003,18 +1090,11 @@ public class Juliac {
*/
public
void
addSrc
(
String
src
)
throws
IOException
{
/*
* Retrieve all source files contained in src.
*/
// Retrieve all source files contained in src
File
baseDir
=
getBaseDir
();
List
<
SourceFile
>
sfs
=
new
ArrayList
<>();
SourceFile
.
addAllJavaFiles
(
baseDir
,
src
,
sfs
);
/*
* Register the source files with the current compilation round.
*/
CompilationRound
round
=
getCompilationRound
();
round
.
addInput
(
sfs
);
addInput
(
sfs
);
srcs
.
add
(
src
);
}
...
...
@@ -1134,16 +1214,9 @@ public class Juliac {
// ----------------------------------------------------------------------
// Setter/getter methods for
loaders and compilation rounds
// Setter/getter methods for
the class loader
// ----------------------------------------------------------------------
public
CompilationRound
getCompilationRound
()
{
if
(
round
==
null
)
{
round
=
new
CompilationRound
(
this
);
}
return
round
;
}
public
ClassLoader
getClassLoader
()
{
if
(
classLoader
==
null
)
{
classLoader
=
getClass
().
getClassLoader
();
...
...
juliac/extension/adlet/core/src/main/java/org/objectweb/fractal/juliac/adlet/MixinProcessor.java
View file @
6b8e7680
...
...
@@ -40,7 +40,6 @@ import javax.lang.model.element.Element;
import
javax.lang.model.element.TypeElement
;
import
javax.tools.JavaFileObject
;
import
org.objectweb.fractal.juliac.CompilationRound
;
import
org.objectweb.fractal.juliac.SourceFileDir
;
import
org.objectweb.fractal.juliac.adlet.api.annotation.Mixin
;
import
org.objectweb.fractal.juliac.adlet.helper.AnnotatedConstructHelper
;
...
...
@@ -150,8 +149,7 @@ public class MixinProcessor extends AbstractJuliacProcessor {
/*
* Add the generated file to the current compilation round.
*/
CompilationRound
round
=
jc
.
getCompilationRound
();
URI
uri
=
sourceFile
.
toUri
();
round
.
addGenerated
(
new
SourceFileDir
(
uri
,
targetClassName
,
"java"
),
null
);
jc
.
addGenerated
(
new
SourceFileDir
(
uri
,
targetClassName
,
"java"
),
null
);
}
}
juliac/extension/adlet/opt-oo/src/main/java/org/objectweb/fractal/juliac/adlet/opt/InitializerOOCtrlClassGenerator.java
View file @
6b8e7680
...
...
@@ -39,7 +39,6 @@ import javax.lang.model.util.Elements;
import
org.objectweb.fractal.api.type.ComponentType
;
import
org.objectweb.fractal.fraclet.annotations.Lifecycle
;
import
org.objectweb.fractal.fraclet.types.Step
;
import
org.objectweb.fractal.juliac.CompilationRound
;
import
org.objectweb.fractal.juliac.Juliac
;
import
org.objectweb.fractal.juliac.adlet.helper.TypeElementHelper
;
import
org.objectweb.fractal.juliac.api.JuliacRuntimeException
;
...
...
@@ -146,10 +145,9 @@ extends org.objectweb.fractal.juliac.fraclet.InitializerOOCtrlClassGenerator {
* by this method. This is then safe to retrieve the corresponding
* information contained in the source type.
*/
CompilationRound
round
=
jc
.
getCompilationRound
();
boolean
b
=
round
.
contains
(
contentClassName
);
boolean
b
=
jc
.
contains
(
contentClassName
);
if
(
b
)
{
cl
=
(
TypeElement
)
round
.
getSourceType
(
contentClassName
);
cl
=
(
TypeElement
)
jc
.
getSourceType
(
contentClassName
);
}
else
{
final
String
msg
=
...
...
juliac/module/spoon/src/main/java/org/objectweb/fractal/juliac/spoon/SpoonSupportImpl.java
View file @
6b8e7680
...
...
@@ -34,7 +34,6 @@ import java.util.Map;
import
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration
;
import
org.eclipse.jdt.internal.compiler.env.ICompilationUnit
;
import
org.objectweb.fractal.juliac.CompilationRound
;
import
org.objectweb.fractal.juliac.Juliac
;
import
org.objectweb.fractal.juliac.SourceFile
;
import
org.objectweb.fractal.juliac.SourceFileDir
;
...
...
@@ -271,8 +270,7 @@ public class SpoonSupportImpl implements SpoonSupportItf {
throw
new
IOException
(
msg
);
}
CompilationRound
round
=
jc
.
getCompilationRound
();
URI
uri
=
files
.
get
(
0
).
toURI
();
round
.
addGenerated
(
new
SourceFileDir
(
uri
,
name
,
"java"
),
null
);
jc
.
addGenerated
(
new
SourceFileDir
(
uri
,
name
,
"java"
),
null
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment