Created
December 8, 2010 22:22
-
-
Save dmachi/734029 to your computer and use it in GitHub Desktop.
maven profile example for generating and copying docs.
This file contains hidden or 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
<profile> | |
<id>docs</id> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>exec-maven-plugin</artifactId> | |
<version>1.2</version> | |
<executions> | |
<execution> | |
<id>build-api-xml</id> | |
<phase>generate-resources</phase> | |
<goals> | |
<goal>exec</goal> | |
</goals> | |
<configuration> | |
<executable>php</executable> | |
<workingDirectory>src/main/webapp/js/util/docscripts</workingDirectory> | |
<arguments> | |
<argument>generate.php</argument> | |
<argument>myNS</argument> <!-- leave this off and it will build for all of them --> | |
<argument>--serialize=xml</argument> | |
<argument>--outfile=../ibm</argument> | |
<argument>--clean</argument> | |
</arguments> | |
</configuration> | |
</execution> | |
<execution> | |
<id>build-docs</id> | |
<phase>process-resources</phase> | |
<goals> | |
<goal>exec</goal> | |
</goals> | |
<configuration> | |
<includeProjectDependencies>false</includeProjectDependencies> | |
<includePluginDependencies>true</includePluginDependencies> | |
<executable>php</executable> | |
<workingDirectory>src/main/resources/docs</workingDirectory> | |
<arguments> | |
<argument>lib/process.php</argument> | |
<argument>../../webapp/js/util/docscripts/ibm.xml</argument> | |
<argument>${project.version}</argument> | |
</arguments> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
<plugin> | |
<artifactId>maven-resources-plugin</artifactId> | |
<version>2.4.3</version> | |
<executions> | |
<execution> | |
<id>copy-resources</id> | |
<phase>validate</phase> | |
<goals> | |
<goal>copy-resources</goal> | |
</goals> | |
<configuration> | |
<includeEmptyDirs>true</includeEmptyDirs> | |
<outputDirectory>${basedir}/target/SMAWebService/docs</outputDirectory> | |
<resources> | |
<resource> | |
<directory>src/main/resources/docs/</directory> | |
</resource> | |
</resources> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</profile> |
This file contains hidden or 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
<?php | |
function remove_dir($path){ | |
$dir = new DirectoryIterator($path); | |
foreach($dir as $f){ | |
if($f->isFile() || $f->isLink()){ | |
unlink($f->getPathName()); | |
} | |
else if(!$f->isDot() && $f->isDir()){ | |
remove_dir($f->getPathName()); | |
} | |
} | |
rmdir($path); | |
} | |
function process($version, $api_xml, $dataDir, $xslDir){ | |
$s = microtime(1); | |
print("Processing $api_xml as $version\n"); | |
if(file_exists($api_xml)){ | |
$api = new DOMDocument(); | |
$api->load($api_xml); | |
print("API xml file load time: " . (microtime(1) - $s)); | |
} | |
// again. | |
if(isset($api)){ | |
print("XSLT Transformation...\n"); | |
// ok, we're good to go. Let's do this. LEERRRROOOOYYYYY a-JENKINS! | |
$ss = array("details", "objects", "provides", "resources"); | |
foreach($ss as $style){ | |
$start = microtime(1); | |
$xsl = new DOMDocument(); | |
$xsl->load($xslDir . '/'. $style . ".xsl"); | |
$p = new XSLTProcessor(); | |
$p->importStylesheet($xsl); | |
$d = new DOMDocument(); | |
$d->loadXML($p->transformToXML($api)); | |
print("Saving ". $dataDir . "/" . $style . ".xml"); | |
$d->save($dataDir . "/" . $style . ".xml"); | |
print($style . " transformation time: " . (microtime(1) - $start)); | |
} | |
print("Total time: " . (microtime(1) - $s)); | |
return true; | |
} | |
return false; | |
} | |
//print_r($argv); | |
if (!empty($argv[1])){ | |
$file = $argv[1]; | |
}else{ | |
$file = getenv("API_XML"); | |
} | |
if (!empty($argv[2])){ | |
$version= $argv[2]; | |
}else { | |
$version= getenv("API_VERSION"); | |
} | |
if (empty($file) || empty($version)){ | |
print("No Version supplied\n"); | |
print("USAGE: process.php API_XML API_VERSION\nor set API_XML and API_VERSION environment vars and run process.php without args\n"); | |
exit(1); | |
} | |
if (!file_exists($file)){ | |
print("Input file not found: " . $file . "\n"); | |
exit(1); | |
} | |
print("Input XML: " . $file . "\n"); | |
print("Input Version: " . $version . "\n"); | |
$dataDir = "data/". $version; | |
$xslDir = "xsl/"; | |
print("DataDir: " . $dataDir . "\n"); | |
if (!is_dir($dataDir)){ | |
print("Creating directory: ".$dataDir."\n"); | |
mkdir($dataDir, 0777,true); | |
} | |
if (!is_dir($dataDir . "/cache")) { | |
mkdir($dataDir . "/cache", 0777, true); | |
} | |
$filename = basename($file); | |
$outfile = $dataDir . "/api.xml"; | |
print("Copying ".$file . ' to ' . $outfile . "\n"); | |
copy($file, $outfile); | |
//print("Processing: ".$outfile."\n"); | |
//print("Processing " . $file . " as version " . $version . "\n\n"); | |
if (process($version,$outfile,$dataDir,$xslDir)) { | |
print("Processing completed successfully."); | |
exit(0); | |
}; | |
print("Processing failed."); | |
exit(1); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment