Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SHRINKDESC-126] JavaDoc incorrect for parameters #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
<id>executionJBossEE6</id>
<phase>validate</phase>
<configuration>
<verbose>true</verbose>
<verbose>false</verbose>
<javadocs>
<javadoc>
<tag>@author</tag>
Expand Down
2 changes: 2 additions & 0 deletions metadata-parser-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<nameSpace>datasources</nameSpace>
<packageApi>org.jboss.datasources.api</packageApi>
<packageImpl>org.jboss.datasources.impl</packageImpl>
<pathToPackageInfoApi>${basedir}/src/test/resources/packageInfo/datasourceApi/package-info.java</pathToPackageInfoApi>
<pathToPackageInfoImpl>${basedir}/src/test/resources/packageInfo/datasourceImpl/package-info.java</pathToPackageInfoImpl>
<descriptorName>DatasourcesDescriptor</descriptorName>
<elementName>datasources</elementName>
<elementType>datasources:datasourcesType</elementType>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the implementation classes as defined in the schema
*/

package org.jboss.datasources.api;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the implementation classes as defined in the schema
*/

package org.jboss.datasources.impl;
6 changes: 6 additions & 0 deletions metadata-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
<version>3.1</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class MetadataDescriptor extends BaseMetadataItem {

private boolean generateClasses;

private String pathToPackageInfoApi;

private String pathToPackageInfoImpl;

private Properties namespaces = new Properties();

public MetadataDescriptor(String name) {
Expand Down Expand Up @@ -68,4 +72,20 @@ public boolean isGenerateClasses() {
public void setGenerateClasses(final boolean generateClasses) {
this.generateClasses = generateClasses;
}

public String getPathToPackageInfoApi() {
return pathToPackageInfoApi;
}

public void setPathToPackageInfoApi(final String pathToPackageInfoApi) {
this.pathToPackageInfoApi = pathToPackageInfoApi;
}

public String getPathToPackageInfoImpl() {
return pathToPackageInfoImpl;
}

public void setPathToPackageInfoImpl(final String pathToPackageInfoImpl) {
this.pathToPackageInfoImpl = pathToPackageInfoImpl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerException;

import org.apache.commons.io.FileUtils;
import org.jboss.shrinkwrap.descriptor.metadata.dom.DomWriter;
import org.jboss.shrinkwrap.descriptor.metadata.dtd.MetadataDtdEventListener;
import org.jboss.shrinkwrap.descriptor.metadata.xslt.XsltTransformer;
Expand Down Expand Up @@ -103,6 +104,9 @@ public void parse(final MetadataParserPath path, final List<?> confList, final L
metadataDescriptor.setNamespace(metadataConf.getNameSpace());
metadataDescriptor.setNamespaces(metadataConf.getNamespaces());
metadataDescriptor.setGenerateClasses(metadataConf.generateClasses);
metadataDescriptor.setPathToPackageInfoApi(metadataConf.getPathToPackageInfoApi());
metadataDescriptor.setPathToPackageInfoImpl(metadataConf.getPathToPackageInfoImpl());

metadata.getMetadataDescriptorList().add(metadataDescriptor);

if (log.isLoggable(Level.FINE)) {
Expand Down Expand Up @@ -155,6 +159,7 @@ public void parse(final MetadataParserPath path, final List<?> confList, final L

if (path.getPathToApi() != null && path.getPathToImpl() != null) {
generateCode(path, verbose);
PackageInfo.copyPackageInfo(path, metadata, verbose);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public class MetadataParserConfiguration {
*/
protected boolean verbose;

/**
* Optional file for package.html or package-info.java
*/
protected String pathToPackageInfoApi;

/**
* Optional file for package.html or package-info.java
*/
protected String pathToPackageInfoImpl;

/**
* The map declaring the name spaces for the given descriptor.
*/
Expand Down Expand Up @@ -156,4 +166,19 @@ public void setGenerateClasses(final boolean generateClasses) {
this.generateClasses = generateClasses;
}

public String getPathToPackageInfoApi() {
return pathToPackageInfoApi;
}

public void setPathToPackageInfoApi(final String pathToPackageInfoApi) {
this.pathToPackageInfoApi = pathToPackageInfoApi;
}

public String getPathToPackageInfoImpl() {
return pathToPackageInfoImpl;
}

public void setPathToPackageInfoImpl(final String pathToPackageInfoImpl) {
this.pathToPackageInfoImpl = pathToPackageInfoImpl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.
*/

package org.jboss.shrinkwrap.descriptor.metadata;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

import org.apache.commons.io.FileUtils;

/**
* This class copies optionally the package info files into source directories.
*
* @author <a href="mailto:[email protected]">Ralf Battenfeld</a>
*/
public final class PackageInfo {
public static final String PACKAGE_HTML_NAME = "package.html";
public static final String PACKAGE_JAVA_NAME = "package-info.java";
private static final Logger log = Logger.getLogger(PackageInfo.class.getName());

/**
* Copies the optional packageInfo files into the packages.
* @param path
* @param metadata
* @throws IOException
*/
public static void copyPackageInfo(final MetadataParserPath path, final Metadata metadata, final boolean verbose) throws IOException {
for (final MetadataDescriptor descriptor : metadata.getMetadataDescriptorList()) {
if (descriptor.getPathToPackageInfoApi() != null) {
final File sourceFile = new File(descriptor.getPathToPackageInfoApi());
final String destDirectory = path.pathToApi + File.separatorChar + descriptor.getPackageApi().replace('.', '/');
deleteExistingPackageInfo(destDirectory, verbose);
copy(sourceFile, destDirectory, verbose);
}

if (descriptor.getPathToPackageInfoImpl() != null) {
final File sourceFile = new File(descriptor.getPathToPackageInfoImpl());
final String destDirectory = path.pathToImpl + File.separatorChar + descriptor.getPackageImpl().replace('.', '/');
deleteExistingPackageInfo(destDirectory, verbose);
copy(sourceFile, destDirectory, verbose);
}
}
}

/**
* Copies the given sourceFile into the specified directory. The source file post fix
* defines which variant of the package info file is created.
* <p>
* If the source file ends with <code>.java</code>, then the destination file name is <code>package-info.java</code>
* otherwise the file name is <code>package.html</code>.
*
* @param sourceFile
* @param destDirectory
* @param verbose
* @throws IOException
*/
public static void copy(final File sourceFile, final String destDirectory, final boolean verbose) throws IOException {
String destFileName = PACKAGE_HTML_NAME;
if (sourceFile.getName().endsWith("java")) {
destFileName = PACKAGE_JAVA_NAME;
}

final File destFile = new File(destDirectory + File.separatorChar + destFileName);
if (verbose) {
log.info(String.format("Copying packageInfo from: %s to: %s", sourceFile.getAbsolutePath(), destFile.getAbsolutePath()));
}

FileUtils.copyFile(sourceFile, destFile, true);
}

/**
* Deletes package.html or package-info.java from the given directory.
* @param destDirectory
* @param verbose
*/
public static void deleteExistingPackageInfo(final String destDirectory, final boolean verbose) {
final File htmlFile = new File(destDirectory + File.separatorChar + PACKAGE_HTML_NAME);
final File javaFile = new File(destDirectory + File.separatorChar + PACKAGE_JAVA_NAME);
final Boolean isHtmlDeleted = FileUtils.deleteQuietly(htmlFile);
final Boolean isJavaDeleted = FileUtils.deleteQuietly(javaFile);

if (verbose) {
log.info(String.format("File %s deleted: %s", htmlFile.getAbsolutePath(), isHtmlDeleted.toString()));
log.info(String.format("File %s deleted: %s", javaFile.getAbsolutePath(), isJavaDeleted.toString()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public void write(final Metadata metadata, final String pathToMetadata,
generateClassApi.setValue(Boolean.toString(descriptor.isGenerateClasses()));
packageApi.setAttributeNode(generateClassApi);

if (descriptor.getPathToPackageInfoApi() != null) {
final Attr pathToPackageInfoApi = doc.createAttribute("packageInfo");
pathToPackageInfoApi.setValue(descriptor.getPathToPackageInfoApi());
packageApi.setAttributeNode(pathToPackageInfoApi);
}

packages.appendChild(packageApi);
}

Expand All @@ -122,6 +128,13 @@ public void write(final Metadata metadata, final String pathToMetadata,
final Attr generateClassImpl = doc.createAttribute("generateClass");
generateClassImpl.setValue(Boolean.toString(descriptor.isGenerateClasses()));
packageImpl.setAttributeNode(generateClassImpl);

if (descriptor.getPathToPackageInfoImpl() != null) {
final Attr pathToPackageInfoImpl = doc.createAttribute("packageInfo");
pathToPackageInfoImpl.setValue(descriptor.getPathToPackageInfoImpl());
packageImpl.setAttributeNode(pathToPackageInfoImpl);
}

packages.appendChild(packageImpl);
}

Expand Down
2 changes: 1 addition & 1 deletion metadata-parser/src/main/resources/META-INF/ddJavaAll.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@
<xsl:value-of select="concat('', '&#10;')"/>
<xsl:value-of select="concat(' /**', '&#10;')"/>
<xsl:value-of select="concat(' * Sets the body text for the element &lt;code&gt;', $pElementName,'&lt;/code&gt; &#10;')"/>
<xsl:value-of select="concat(' * @param ', xdd:checkForReservedKeywords(xdd:createCamelizedName($pElementName)), ' the value for the body text &lt;code&gt;', $pElementName,'&lt;/code&gt; &#10;')"/>
<xsl:value-of select="concat(' * @param ', 'value', ' the value for the body text &lt;code&gt;', $pElementName,'&lt;/code&gt; &#10;')"/>
<xsl:value-of select="concat(' * @return ', 'the current instance of &lt;code&gt;', $pReturnTypeName, '&lt;/code&gt; &#10;')"/>
<xsl:value-of select="concat(' */', '&#10;')"/>
<xsl:choose>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.jboss.shrinkwrap.descriptor.metadata;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class PackageInfoTest {

@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Test
public void testCopyAndDeleteHtmlFile() throws IOException {
final File packageFile = new File("src/test/resources/package-info-impl.html");
PackageInfo.copy(packageFile, folder.getRoot().getAbsolutePath(), true);
final File destFile = new File(folder.getRoot().getAbsolutePath() + File.separatorChar + PackageInfo.PACKAGE_HTML_NAME);
assertTrue(destFile.exists());

PackageInfo.deleteExistingPackageInfo(folder.getRoot().getAbsolutePath(), true);
assertFalse(destFile.exists());
}

@Test
public void testCopyJavaFile() throws IOException {
final File packageFile = new File("src/test/resources/package-info-api.java");
PackageInfo.copy(packageFile, folder.getRoot().getAbsolutePath(), true);
final File destFile = new File(folder.getRoot().getAbsolutePath() + File.separatorChar + PackageInfo.PACKAGE_JAVA_NAME);
assertTrue(destFile.exists());

PackageInfo.deleteExistingPackageInfo(folder.getRoot().getAbsolutePath(), true);
assertFalse(destFile.exists());
}

}
5 changes: 5 additions & 0 deletions metadata-parser/src/test/resources/package-info-api.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the implementation classes as defined in the schema
*/

package org.jboss.datasources.api;
5 changes: 5 additions & 0 deletions metadata-parser/src/test/resources/package-info-impl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Provides the implementation classes as defined in the schema
*/

package org.jboss.datasources.impl;