Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring

  • Loading branch information...
commit 3c762e2e8f8840df01340c875d944af8aa7baed4 1 parent 9154539
@cbeams cbeams authored
View
2  .gitignore
@@ -1,6 +1,6 @@
.gradle
build
-!src/main/groovy/org/springframework/build
+!*/src/*/*/org/springframework/build
*.sw?
.classpath
.project
View
BIN  .wrapper/gradle-wrapper.jar
Binary file not shown
View
4 .wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Nov 01 19:54:31 PDT 2011
+#Thu Dec 22 11:37:07 CET 2011
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-5-bin.zip
+distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-6-bin.zip
View
21 build.gradle
@@ -1,9 +1,9 @@
buildscript {
repositories {
- mavenRepo url: 'https://repo.springsource.org/plugins-snapshot'
+ maven { url 'https://repo.springsource.org/plugins-release' }
}
dependencies {
- classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.0.x-SNAPSHOT'
+ classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.0.7'
}
}
@@ -16,25 +16,25 @@ subprojects {
apply plugin: 'maven'
apply plugin: 'eclipse'
+ group = 'org.springframework.build.gradle'
+
repositories {
- mavenRepo url: 'https://repo.springsource.org/libs-release'
+ maven { url 'https://repo.springsource.org/libs-release' }
}
dependencies {
- //groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.8.3'
compile gradleApi()
groovy localGroovy()
}
}
project(':gradle-bundlor-plugin') {
- group = 'org.springframework.build.bundlor'
- version = '1.0.0-SNAPSHOT'
+ dependencies {
+ }
}
+/*
project(':gradle-docbook-plugin') {
- group = 'org.springframework.build.docbook'
- version = '1.0.0-SNAPSHOT'
dependencies {
compile 'org.apache.xerces:resolver:2.9.1',
'saxon:saxon:6.5.3',
@@ -52,12 +52,13 @@ project(':gradle-docbook-plugin') {
'org.apache.avalon.framework:avalon-framework-api:4.3.1'
}
}
+*/
repoUser = project.properties['REPO_USERNAME']
repoPass = project.properties['REPO_PASSWORD']
gradle.taskGraph.whenReady {taskGraph ->
- if (taskGraph.hasTask(':artifactoryPublish') &&
+ if (taskGraph.hasTask(':docbook-reference-plugin:artifactoryPublish') &&
(repoUser == null || repoPass == null)) {
throw new InvalidUserDataException(
"Please provide REPO_USERNAME and REPO_PASSWORD properties")
@@ -88,5 +89,5 @@ artifactory {
task wrapper(type:Wrapper) {
jarFile = ".wrapper/gradle-wrapper.jar";
- gradleVersion='1.0-milestone-5'
+ gradleVersion='1.0-milestone-6'
}
View
2  docbook-reference-plugin/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'groovy'
apply plugin: 'maven'
group = 'org.springframework.build.docbook'
-version = '1.0.0-SNAPSHOT'
+version = '0.1.0-SNAPSHOT'
repositories {
mavenCentral()
View
1  docbook-reference-plugin/gradle.properties
@@ -0,0 +1 @@
+version = 0.1.0-SNAPSHOT
View
1  gradle-bundlor-plugin/gradle.properties
@@ -0,0 +1 @@
+version = 1.0.0-SNAPSHOT
View
0  ...ndlor-plugin/src/main/groovy/BundlorPlugin.groovy → ...pringframework/build/bundlor/BundlorPlugin.groovy
File renamed without changes
View
315 gradle-docbook-plugin/docbook.gradle
@@ -0,0 +1,315 @@
+/*
+ * Copyright 2002-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.tools.CatalogResolver;
+
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.*;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.util.zip.*;
+
+import org.apache.fop.apps.*;
+
+import org.gradle.api.logging.LogLevel;
+
+import com.icl.saxon.TransformerFactoryImpl;
+import ch.qos.logback.classic.Level;
+import org.slf4j.LoggerFactory;
+
+buildscript {
+ repositories {
+ mavenCentral()
+ mavenRepo name: 'Shibboleth Repo', urls: 'http://shibboleth.internet2.edu/downloads/maven2'
+ }
+ dependencies {
+ def fopDeps = ['org.apache.xmlgraphics:fop:0.95-1@jar',
+ 'org.apache.xmlgraphics:xmlgraphics-commons:1.3',
+ 'org.apache.xmlgraphics:batik-bridge:1.7@jar',
+ 'org.apache.xmlgraphics:batik-util:1.7@jar',
+ 'org.apache.xmlgraphics:batik-css:1.7@jar',
+ 'org.apache.xmlgraphics:batik-dom:1.7',
+ 'org.apache.xmlgraphics:batik-svg-dom:1.7@jar',
+ 'org.apache.avalon.framework:avalon-framework-api:4.3.1']
+
+ classpath 'org.apache.xerces:resolver:2.9.1',
+ 'saxon:saxon:6.5.3',
+ 'org.apache.xerces:xercesImpl:2.9.1',
+ fopDeps,
+ 'net.sf.xslthl:xslthl:2.0.1',
+ 'net.sf.docbook:docbook-xsl:1.75.2:resources@zip'
+ }
+
+}
+
+/**
+ * Gradle Docbook plugin implementation.
+ * <p>
+ * Creates three tasks: docbookHtml, docbookHtmlSingle and docbookPdf.
+ * Each task takes a single File on which it operates.
+ *
+ * @author Luke Taylor
+ */
+// Add the plugin tasks to the project
+task docbookHtml(type: DocbookHtml) {
+ setDescription('Generates chunked docbook html output.')
+ xdir = 'html'
+ classpath = buildscript.configurations.classpath
+}
+
+task docbookHtmlSingle(type: Docbook) {
+ setDescription('Generates single page docbook html output.')
+ xdir = 'htmlsingle'
+ classpath = buildscript.configurations.classpath
+}
+
+task docbookPdf(type: DocbookFoPdf) {
+ setDescription('Generates PDF docbook output.')
+ extension = 'fo'
+ xdir = 'pdf'
+ classpath = buildscript.configurations.classpath
+}
+
+/**
+ */
+public class Docbook extends DefaultTask {
+ @Input
+ String extension = 'html';
+
+ @Input
+ boolean XIncludeAware = true;
+
+ @Input
+ boolean highlightingEnabled = true;
+
+ String admonGraphicsPath;
+
+ @InputDirectory
+ File sourceDirectory = new File(project.getProjectDir(), "build/reference-work");
+
+ @Input
+ String sourceFileName;
+
+ @InputFile
+ File stylesheet;
+
+ @OutputDirectory
+ File docsDir = new File(project.getBuildDir(), "reference");
+
+ @InputFiles
+ Configuration classpath
+
+ @TaskAction
+ public final void transform() {
+ // the docbook tasks issue spurious content to the console. redirect to INFO level
+ // so it doesn't show up in the default log level of LIFECYCLE unless the user has
+ // run gradle with '-d' or '-i' switches -- in that case show them everything
+ switch (project.gradle.startParameter.logLevel) {
+ case LogLevel.DEBUG:
+ case LogLevel.INFO:
+ break;
+ default:
+ logging.captureStandardOutput(LogLevel.INFO)
+ logging.captureStandardError(LogLevel.INFO)
+ }
+
+ SAXParserFactory factory = new org.apache.xerces.jaxp.SAXParserFactoryImpl();
+ factory.setXIncludeAware(XIncludeAware);
+ docsDir.mkdirs();
+
+ File srcFile = new File(sourceDirectory, sourceFileName);
+ String outputFilename = srcFile.getName().substring(0, srcFile.getName().length() - 4) + '.' + extension;
+
+ File oDir = new File(getDocsDir(), xdir)
+ File outputFile = new File(oDir, outputFilename);
+
+ Result result = new StreamResult(outputFile.getAbsolutePath());
+ CatalogResolver resolver = new CatalogResolver(createCatalogManager());
+ InputSource inputSource = new InputSource(srcFile.getAbsolutePath());
+
+ XMLReader reader = factory.newSAXParser().getXMLReader();
+ reader.setEntityResolver(resolver);
+ TransformerFactory transformerFactory = new TransformerFactoryImpl();
+ transformerFactory.setURIResolver(resolver);
+ URL url = stylesheet.toURL();
+ Source source = new StreamSource(url.openStream(), url.toExternalForm());
+ Transformer transformer = transformerFactory.newTransformer(source);
+
+ if (highlightingEnabled) {
+ File highlightingDir = new File(getProject().getBuildDir(), "highlighting");
+ if (!highlightingDir.exists()) {
+ highlightingDir.mkdirs();
+ extractHighlightFiles(highlightingDir);
+ }
+
+ transformer.setParameter("highlight.source", "1");
+ transformer.setParameter("highlight.xslthl.config", new File(highlightingDir, "xslthl-config.xml").toURI().toURL());
+
+ if (admonGraphicsPath != null) {
+ transformer.setParameter("admon.graphics", "1");
+ transformer.setParameter("admon.graphics.path", admonGraphicsPath);
+ }
+ }
+
+ preTransform(transformer, srcFile, outputFile);
+
+ transformer.transform(new SAXSource(reader, inputSource), result);
+
+ postTransform(outputFile);
+ }
+
+ private void extractHighlightFiles(File toDir) {
+ File docbookZip = classpath.files.find { file -> file.name.contains('docbook-xsl-')};
+
+ if (docbookZip == null) {
+ throw new GradleException("Docbook zip file not found");
+ }
+
+ ZipFile zipFile = new ZipFile(docbookZip);
+
+ Enumeration e = zipFile.entries();
+ while (e.hasMoreElements()) {
+ ZipEntry ze = (ZipEntry) e.nextElement();
+ if (ze.getName().matches(".*/highlighting/.*\\.xml")) {
+ String filename = ze.getName().substring(ze.getName().lastIndexOf("/highlighting/") + 14);
+ copyFile(zipFile.getInputStream(ze), new File(toDir, filename));
+ }
+ }
+ }
+
+ private void copyFile(InputStream source, File destFile) {
+ destFile.createNewFile();
+ FileOutputStream to = null;
+ try {
+ to = new FileOutputStream(destFile);
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+
+ while ((bytesRead = source.read(buffer)) > 0) {
+ to.write(buffer, 0, bytesRead);
+ }
+ } finally {
+ if (source != null) {
+ source.close();
+ }
+ if (to != null) {
+ to.close();
+ }
+ }
+ }
+
+ protected void preTransform(Transformer transformer, File sourceFile, File outputFile) {
+ }
+
+ protected void postTransform(File outputFile) {
+ }
+
+ private CatalogManager createCatalogManager() {
+ CatalogManager manager = new CatalogManager();
+ manager.setIgnoreMissingProperties(true);
+ ClassLoader classLoader = this.getClass().getClassLoader();
+ StringBuilder builder = new StringBuilder();
+ String docbookCatalogName = "docbook/catalog.xml";
+ URL docbookCatalog = classLoader.getResource(docbookCatalogName);
+
+ if (docbookCatalog == null) {
+ throw new IllegalStateException("Docbook catalog " + docbookCatalogName + " could not be found in " + classLoader);
+ }
+
+ builder.append(docbookCatalog.toExternalForm());
+
+ Enumeration enumeration = classLoader.getResources("/catalog.xml");
+ while (enumeration.hasMoreElements()) {
+ builder.append(';');
+ URL resource = (URL) enumeration.nextElement();
+ builder.append(resource.toExternalForm());
+ }
+ String catalogFiles = builder.toString();
+ manager.setCatalogFiles(catalogFiles);
+ return manager;
+ }
+}
+
+/**
+ */
+class DocbookHtml extends Docbook {
+
+ @Override
+ protected void preTransform(Transformer transformer, File sourceFile, File outputFile) {
+ String rootFilename = outputFile.getName();
+ rootFilename = rootFilename.substring(0, rootFilename.lastIndexOf('.'));
+ transformer.setParameter("root.filename", rootFilename);
+ transformer.setParameter("base.dir", outputFile.getParent() + File.separator);
+ }
+}
+
+/**
+ */
+class DocbookFoPdf extends Docbook {
+
+ /**
+ * <a href="http://xmlgraphics.apache.org/fop/0.95/embedding.html#render">From the FOP usage guide</a>
+ */
+ @Override
+ protected void postTransform(File foFile) {
+ FopFactory fopFactory = FopFactory.newInstance();
+
+ OutputStream out = null;
+ final File pdfFile = getPdfOutputFile(foFile);
+ logger.debug("Transforming 'fo' file " + foFile + " to PDF: " + pdfFile);
+
+ try {
+ out = new BufferedOutputStream(new FileOutputStream(pdfFile));
+
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
+
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+
+ Source src = new StreamSource(foFile);
+
+ Result res = new SAXResult(fop.getDefaultHandler());
+
+ switch (project.gradle.startParameter.logLevel) {
+ case LogLevel.DEBUG:
+ case LogLevel.INFO:
+ break;
+ default:
+ // only show verbose fop output if the user has specified 'gradle -d' or 'gradle -i'
+ LoggerFactory.getILoggerFactory().getLogger('org.apache.fop').level = Level.ERROR
+ }
+
+ transformer.transform(src, res);
+
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+
+ if (!foFile.delete()) {
+ logger.warn("Failed to delete 'fo' file " + foFile);
+ }
+ }
+
+ private File getPdfOutputFile(File foFile) {
+ return new File(foFile.parent, this.project.rootProject.name + '-reference.pdf')
+ }
+}
View
0  ...cbook-plugin/src/main/groovy/DocbookPlugin.groovy → ...pringframework/build/docbook/DocbookPlugin.groovy
File renamed without changes
View
151 gradle-docbook-plugin/src/main/groovy/org/springframework/build/docbook/DocbookTransformer.java
@@ -0,0 +1,151 @@
+package org.springframework.build.docbook;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.xalan.processor.TransformerFactoryImpl;
+import org.apache.xerces.jaxp.SAXParserFactoryImpl;
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.tools.CatalogResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+/**
+ * Accept a source file.
+ * transform it to chunked HTML
+ * with images
+ * with syntax highlighting
+ * with ${...} replacement
+ *
+ * @author Chris Beams
+ */
+public class DocbookTransformer {
+
+ private boolean xIncludeAware = true;
+ private String sourceFilePath;
+ private String stylesheetPath;
+
+ public void setXIncludeAware(boolean xIncludeAware) {
+ this.xIncludeAware = xIncludeAware;
+ }
+
+ public void setSourceFilePath(String sourceFilePath) {
+ this.sourceFilePath = sourceFilePath;
+ }
+
+ public void setStylesheetPath(String stylesheetPath) {
+ this.stylesheetPath = stylesheetPath;
+ }
+
+ public void transform() throws Exception {
+
+ if (sourceFilePath == null)
+ throw new IllegalArgumentException("sourceFilePath must not be null");
+ if (stylesheetPath == null)
+ throw new IllegalArgumentException("stylesheetPath must not be null");
+
+ SAXParserFactory factory = new SAXParserFactoryImpl();
+ factory.setXIncludeAware(xIncludeAware);
+
+ File srcFile = new File(sourceFilePath);
+ String outputFilename = srcFile.getName().substring(0, srcFile.getName().length() - 4) + '.' + "html";
+
+ File oDir = new File("/tmp");
+ File outputFile = new File(oDir, outputFilename);
+
+ Result result = new StreamResult(outputFile.getAbsolutePath());
+ CatalogResolver resolver = new CatalogResolver(createCatalogManager());
+ InputSource inputSource = new InputSource(srcFile.getAbsolutePath());
+
+ XMLReader reader = factory.newSAXParser().getXMLReader();
+ reader.setEntityResolver(resolver);
+ TransformerFactory transformerFactory = new TransformerFactoryImpl();
+ transformerFactory.setURIResolver(resolver);
+ File stylesheet = new File(stylesheetPath);
+ URL url = stylesheet.toURL();
+ Source source = new StreamSource(url.openStream(), url.toExternalForm());
+ Transformer transformer = transformerFactory.newTransformer(source);
+
+ transformer.transform(new SAXSource(reader, inputSource), result);
+
+ /*
+  docsDir.mkdirs();
+
+  File srcFile = new File(sourceDirectory, sourceFileName);
+  String outputFilename = srcFile.getName().substring(0, srcFile.getName().length() - 4) + '.' + extension;
+
+  File oDir = new File(getDocsDir(), xdir)
+  File outputFile = new File(oDir, outputFilename);
+
+  Result result = new StreamResult(outputFile.getAbsolutePath());
+  CatalogResolver resolver = new CatalogResolver(createCatalogManager());
+  InputSource inputSource = new InputSource(srcFile.getAbsolutePath());
+
+  XMLReader reader = factory.newSAXParser().getXMLReader();
+  reader.setEntityResolver(resolver);
+  TransformerFactory transformerFactory = new TransformerFactoryImpl();
+  transformerFactory.setURIResolver(resolver);
+  URL url = stylesheet.toURL();
+  Source source = new StreamSource(url.openStream(), url.toExternalForm());
+  Transformer transformer = transformerFactory.newTransformer(source);
+
+  if (highlightingEnabled) {
+   File highlightingDir = new File(getProject().getBuildDir(), "highlighting");
+   if (!highlightingDir.exists()) {
+    highlightingDir.mkdirs();
+    extractHighlightFiles(highlightingDir);
+   }
+
+   transformer.setParameter("highlight.source", "1");
+   transformer.setParameter("highlight.xslthl.config", new File(highlightingDir, "xslthl-config.xml").toURI().toURL());
+
+   if (admonGraphicsPath != null) {
+    transformer.setParameter("admon.graphics", "1");
+    transformer.setParameter("admon.graphics.path", admonGraphicsPath);
+   }
+  }
+
+  preTransform(transformer, srcFile, outputFile);
+
+  transformer.transform(new SAXSource(reader, inputSource), result);
+
+  postTransform(outputFile);
+  */
+ }
+
+ private CatalogManager createCatalogManager() throws IOException {
+ CatalogManager manager = new CatalogManager();
+ manager.setIgnoreMissingProperties(true);
+ ClassLoader classLoader = this.getClass().getClassLoader();
+ StringBuilder builder = new StringBuilder();
+ String docbookCatalogName = "docbook/catalog.xml";
+ URL docbookCatalog = classLoader.getResource(docbookCatalogName);
+
+ if (docbookCatalog == null) {
+ throw new IllegalStateException("Docbook catalog " + docbookCatalogName + " could not be found in " + classLoader);
+ }
+
+ builder.append(docbookCatalog.toExternalForm());
+
+ Enumeration enumeration = classLoader.getResources("/catalog.xml");
+ while (enumeration.hasMoreElements()) {
+ builder.append(';');
+ URL resource = (URL) enumeration.nextElement();
+ builder.append(resource.toExternalForm());
+ }
+ String catalogFiles = builder.toString();
+ manager.setCatalogFiles(catalogFiles);
+ return manager;
+ }
+}
View
13 gradle-docbook-plugin/src/test/groovy/org/springframework/build/docbook/DocbookTransformerTests.java
@@ -0,0 +1,13 @@
+package org.springframework.build.docbook;
+
+import org.junit.Test;
+
+public class DocbookTransformerTests {
+ @Test
+ public void test() throws Exception {
+ DocbookTransformer dt = new DocbookTransformer();
+ dt.setSourceFilePath("/tmp/index.xml");
+ dt.setStylesheetPath("/tmp/stylesheet.xsl");
+ dt.transform();
+ }
+}
View
4 settings.gradle
@@ -1,3 +1,5 @@
+rootProject.name = 'gradle-plugins'
+
include 'gradle-bundlor-plugin'
-include 'gradle-docbook-plugin'
+//include 'gradle-docbook-plugin'
include 'docbook-reference-plugin'
View
4 wrapper.gradle
@@ -0,0 +1,4 @@
+task wrapper(type:Wrapper) {
+ jarFile = ".wrapper/gradle-wrapper.jar"
+ gradleVersion='1.0-milestone-6'
+}
Please sign in to comment.
Something went wrong with that request. Please try again.