Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Nov 22, 2013
1 parent c5d31c4 commit a876f5b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ publishing {

model {
tasks.generatePomFileForMavenJavaPublication {
destination = file("$buildDir/generated-pom.xml")
destination = file( "$project.buildDir/generated-pom.xml" )
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,36 @@ class BookEnvironment implements Environment, MasterLanguageDescriptor {
this.masterLanguageDescriptor = this
this.resourceDelegate = new ResourceDelegate()
this.outputDirName = "${project.buildDir}/docbook"
this.workDirName = outputDirName + "/work"
this.stageDirName = outputDirName + "/stage"
this.publishDirName = outputDirName + "/publish"
this.profileDirName = outputDirName + "/profile"
this.workDirName = "$outputDirName/work/${book.name}"
this.stageDirName = "$outputDirName/stage/${book.name}"
this.publishDirName = "$outputDirName/publish/${book.name}"
this.profileDirName = "$outputDirName/profile/${book.name}"
}

Locale getLanguage() {
if (language == null)
language = getLanguage(book.masterLanguage)
if ( language == null ) {
language = getLanguage( book.masterLanguage )
}
return language
}

Locale getLanguage(lang) {
TranslationUtils.parse(lang, book.localeSeparator)
Locale getLanguage(String lang) {
TranslationUtils.parse( lang, book.localeSeparator )
}

public ResourceDelegate getResourceDelegate() {
return resourceDelegate
}

Set<File> getDocumentFiles() {
if (documentFiles == null) {
if ( documentFiles == null ) {
documentFiles = [] as Set
documentFiles << getRootDocumentFile()
XIncludeHelper.findAllInclusionFiles(getRootDocumentFile(), documentFiles, getDocBookSchemaResolutionStrategy());
XIncludeHelper.findAllInclusionFiles(
getRootDocumentFile(),
documentFiles,
getDocBookSchemaResolutionStrategy()
);
}
return documentFiles
}
Expand All @@ -105,50 +106,58 @@ class BookEnvironment implements Environment, MasterLanguageDescriptor {
private ClassLoader buildResourceDelegateClassLoader() {
List<URL> urls = new ArrayList<URL>();

if (stagingDirectory.exists()) {
if ( stagingDirectory.exists() ) {
try {
urls.add(stagingDirectory.toURI().toURL());
urls.add( stagingDirectory.toURI().toURL() );
}
catch (MalformedURLException e) {
throw new JDocBookProcessException("Unable to resolve staging directory to URL", e);
throw new JDocBookProcessException( "Unable to resolve staging directory to URL", e );
}
}

// Closure visited on numerous Gradle Configurations used to collect the dependency artifact URLs into
// the urls List
def feedingClasspathWithDependencies = { Configuration configuration ->
configuration.files.each { File file ->
try {
urls.add(file.toURI().toURL());
}
catch (MalformedURLException e) {
catch (MalformedURLException ignore) {
log.warn("Unable to retrieve file url [" + file.getAbsolutePath() + "]; ignoring");
}
}
}
feedingClasspathWithDependencies( project.configurations[ "${JDocBookPlugin.DOCBOOK_CONFIG_NAME}" ] )
feedingClasspathWithDependencies( project.buildscript.configurations[ "${ScriptHandler.CLASSPATH_CONFIGURATION}" ] )
feedingClasspathWithDependencies( project.configurations[ "${JDocBookPlugin.STYLES_CONFIG_NAME}" ] )
feedingClasspathWithDependencies( project.configurations[ "${JDocBookPlugin.XSL_CONFIG_NAME}" ] )

feedingClasspathWithDependencies(project.configurations."${JDocBookPlugin.DOCBOOK_CONFIG_NAME}")
feedingClasspathWithDependencies(project.buildscript.configurations."${ScriptHandler.CLASSPATH_CONFIGURATION}")
feedingClasspathWithDependencies(project.configurations."${JDocBookPlugin.STYLES_CONFIG_NAME}")
feedingClasspathWithDependencies(project.configurations."${JDocBookPlugin.XSL_CONFIG_NAME}")
return new URLClassLoader( urls.toArray(new URL[urls.size()]), Thread.currentThread().contextClassLoader);
return new URLClassLoader(
urls.toArray(new URL[urls.size()]),
// TCCL here should be the "expanded buildscript ClassLoader" as expanded by ScriptClassLoaderExtender
// which it then pushes to TCCL
Thread.currentThread().contextClassLoader
);
}

File getWorkDirectory() {
project.file(workDirName)
project.file( workDirName )
}

File getWorkDirPerLang(lang) {
new File(workDirectory, lang)
File getWorkDirPerLang(String lang) {
new File( workDirectory, lang )
}

File getProfileDirPerLang(lang) {
new File(profileDirName, lang)
File getProfileDirPerLang(String lang) {
project.file( "$profileDirName/$lang" )
}

File getPublishDirPerLang(lang) {
project.file("$publishDirName/$lang")
File getPublishDirPerLang(String lang) {
project.file( "$publishDirName/$lang" )
}

File getStagingDirectory() {
project.file(stageDirName)
project.file( stageDirName )
}

private List<File> fontDirectories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ public class GenerateXslFoTask extends BookTask implements RenderingSource {

private FormatOptions findPdfFormatOptions() {
def format = book.formats.findByName(StandardDocBookFormatMetadata.PDF.name)
if (format == null)
throw new JDocBookProcessException("Could not locate PDF format options");
if (format == null) {
throw new JDocBookProcessException("Could not locate PDF format options")
}
return format
}

File resolveSourceDocument() { getSourceDocument() }
File resolveSourceDocument() {
getSourceDocument()
}

@InputFile
File getSourceDocument() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,49 @@ private Result(ClassLoader originalTccl) {
}
}

private static final Result NO_EXTENSION_RESULT = new Result( null );

public static synchronized Result extendScriptClassLoader(Project project) {
log.lifecycle( "Extending script classloader with the {} dependencies", JDocBookPlugin.XSL_CONFIG_NAME );

List<URL> xslDepUrls = null;

final java.util.Set<java.io.File> xslDepFiles = project.getConfigurations()
.getByName( JDocBookPlugin.XSL_CONFIG_NAME )
.getFiles();
if ( xslDepFiles == null || xslDepFiles.isEmpty() ) {
return NO_EXTENSION_RESULT;
}
if ( ! xslDepFiles.isEmpty() ) {
// This will be used to collect the 'jdocbookXsl' Configuration files (dependencies) to build our extended
// ClassLoader
xslDepUrls = new ArrayList<URL>();

// This will be used to collect the 'jdocbookXsl' Configuration files (dependencies) to build our extended
// ClassLoader
List<URL> xslDepUrls = new ArrayList<URL>();

for ( File xslDepFile : xslDepFiles ) {
try {
log.trace( " Adding artifact to script classloader extension : " + xslDepFile.getPath() );
xslDepUrls.add( xslDepFile.toURI().toURL() );
}
catch (MalformedURLException e) {
log.warn( "Unable to retrieve file url [{}]; ignoring", xslDepFile.getAbsolutePath() );
for ( File xslDepFile : xslDepFiles ) {
try {
log.trace( " Adding artifact to script classloader extension : " + xslDepFile.getPath() );
xslDepUrls.add( xslDepFile.toURI().toURL() );
}
catch (MalformedURLException e) {
log.warn( "Unable to retrieve file url [{}]; ignoring", xslDepFile.getAbsolutePath() );
}
}
}

if ( xslDepUrls.isEmpty() ) {
return NO_EXTENSION_RESULT;
}
final Result tcclResult = new Result( Thread.currentThread().getContextClassLoader() );

// build a new ClassLoader to use as TCCL. This new ClassLoader will use the "buildscript" ClassLoader from
// Gradle as its parent
final URLClassLoader extendedClassLoader = new URLClassLoader(
xslDepUrls.toArray( new URL[ xslDepUrls.size() ] ),
project.getBuildscript().getClassLoader()
);
if ( xslDepUrls == null ) {
Thread.currentThread().setContextClassLoader( project.getBuildscript().getClassLoader() );
}
else {
// build a new ClassLoader to use as TCCL. This new ClassLoader will use the "buildscript" ClassLoader from
// Gradle as its parent
final URLClassLoader extendedClassLoader = new URLClassLoader(
xslDepUrls.toArray( new URL[ xslDepUrls.size() ] ),
project.getBuildscript().getClassLoader()
);
Thread.currentThread().setContextClassLoader( extendedClassLoader );
}

Result result = new Result( Thread.currentThread().getContextClassLoader() );
Thread.currentThread().setContextClassLoader( extendedClassLoader );
return result;
return tcclResult;
}

public static synchronized void unextendScriptClassLoader(Result extensionResult) {
if ( extensionResult == NO_EXTENSION_RESULT ) {
return;
}
Thread.currentThread().setContextClassLoader( extensionResult.originalTccl );
}
}

0 comments on commit a876f5b

Please sign in to comment.