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-125] Add exportAsString-esque facility for Node SPI #88

Open
wants to merge 8 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
5 changes: 2 additions & 3 deletions ant/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 2 additions & 3 deletions api-base/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.jboss.shrinkwrap.descriptor.api;

import org.jboss.shrinkwrap.descriptor.api.formatter.Formatter;
import org.jboss.shrinkwrap.descriptor.api.formatter.Formatters;

/**
* Represents a child element in a hierarchial {@link Descriptor} structure capable of navigating up a level to its
* parent
Expand All @@ -31,4 +34,16 @@ public interface Child<T> {
* @return The parent of this {@link Child}
*/
T up();

/**
* If "true" is specified, acts as a shorthand for {@link Child#toString(Formatter)} where the
* {@link Formatters#XML} is default.
*/
String toString(final boolean verbose);

/**
* Returns a pretty formatted XML string as returned from the specified {@link Formatter}. Common options may be to
* use the predefined formatters located in {@link Formatters}
*/
String toString(final Formatter formatter) throws IllegalArgumentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.OutputStream;

import org.jboss.shrinkwrap.descriptor.api.formatter.Formatter;

/**
* End-user domain-specific language (DSL) view of a metadata Descriptor.
*
Expand Down Expand Up @@ -55,4 +57,18 @@ public interface Descriptor {
*/
void exportTo(OutputStream output) throws DescriptorExportException, IllegalArgumentException;

/**
* If "true" is specified, acts as a shorthand for {@link Descriptor#toString(Formatter)} where the
* {@link Formatters#XML} is default.
*
* @return
*/
String toString(boolean verbose);

/**
* Returns a pretty formatted XML string as returned from the specified {@link Formatter}. Common options may be to
* use the predefined formatters located in {@link Formatters}.
*/
String toString(Formatter formatter) throws IllegalArgumentException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, 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.api.formatter;

import org.jboss.shrinkwrap.descriptor.api.Descriptor;

/**
* A type capable of formatting an {@link Descriptor} into human-readable style.
*
* @author <a href="mailto:[email protected]">Ralf Battenfeld</a>
* @version $Revision: $
*/
public interface Formatter {

/**
* Returns a formatted view of the specified descriptor
*
* @param descriptor
* @return
* @throws IllegalArgumentException
* If the descriptor is not specified
*/
String format(Descriptor descriptor) throws IllegalArgumentException;


/**
* Returns a pretty formatted XML string.
*
* @param xmlString
* @return
* @throws IllegalArgumentException
* If the descriptor is not specified
*/
String format(String xmlString) throws IllegalArgumentException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, 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.api.formatter;

import org.jboss.shrinkwrap.descriptor.api.Descriptor;

/**
* Available pre-configured {@link Formatter} instances used in constructing a human-readable form for a specified
* {@link Archive}.
*
* @author <a href="mailto:[email protected]">Ralf Battenfeld</a>
* @version $Revision: $
*/
public enum Formatters implements Formatter {

// -------------------------------------------------------------------------------------||
// Types -------------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* {@link Formatter} implementation to provide an "ls -l"-esque output for an {@link Archive}, listing all internal
* contents in sorted order.
*/
XML(XmlFormatter.INSTANCE);


// -------------------------------------------------------------------------------------||
// Internal Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* Internal formatter type, used as a delegate to make {@link Formatters} itself a {@link Formatter}
*/
private final Formatter formatter;

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* Constructs a new {@link Formatters} type using the specified underlying {@link Formatter}
*/
Formatters(final Formatter formatter) {
this.formatter = formatter;
}

// -------------------------------------------------------------------------------------||
// Required Implementations ------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.descriptor.api.formatter.Formatter#format(org.jboss.shrinkwrap.descriptor.api.Descriptor)
*/
@Override
public String format(final Descriptor descriptor) throws IllegalArgumentException {
return formatter.format(descriptor);
}

/**
* {@inheritDoc}
*
* @see org.jboss.shrinkwrap.descriptor.api.formatter.Formatter#format(java.lang.String)
*/
@Override
public String format(final String xmlString) throws IllegalArgumentException {
return formatter.format(xmlString);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, 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.api.formatter;

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.jboss.shrinkwrap.descriptor.api.Descriptor;


/**
* {@link Formatter} implementation to provide a pretty formatted XML string of an {@link Descriptor}.
*
* @author <a href="mailto:[email protected]">Ralf Battenfeld</a>
* @version $Revision: $
*/
enum XmlFormatter implements Formatter {
INSTANCE;

@Override
public String format(Descriptor descriptor) throws IllegalArgumentException {
return formatAsXml(descriptor.exportAsString(), 2);
}

@Override
public String format(String xmlString) throws IllegalArgumentException {
return formatAsXml(xmlString, 2);
}

/**
* Returns a pretty formatted XML string.
* @param input the unformatted XML string.
* @param indent the number of spaces used formatting nested tags.
* @return a pretty formatted XML string.
*/
private String formatAsXml(final String input, final int indent) {
try {
final Source xmlInput = new StreamSource(new StringReader(input));
final StringWriter stringWriter = new StringWriter();
final StreamResult xmlOutput = new StreamResult(stringWriter);
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", indent);
final Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(xmlInput, xmlOutput);
return xmlOutput.getWriter().toString();
} catch (Exception e) {
throw new RuntimeException(e); // simple exception handling, please review it
}
}

}
2 changes: 1 addition & 1 deletion api-javaee-prototype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 2 additions & 3 deletions api-javaee/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 2 additions & 3 deletions api-jboss/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 2 additions & 3 deletions api-misc/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 2 additions & 3 deletions bom/pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vi:ts=2:sw=2:expandtab: -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-bom</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ShrinkWrap Descriptors Bill of Materials</name>
<description>Centralized dependencyManagement for the ShrinkWrap Descriptors Project</description>
Expand Down
5 changes: 2 additions & 3 deletions build-resources/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
5 changes: 2 additions & 3 deletions depchain/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vi:ts=2:sw=2:expandtab: -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Parent -->
<parent>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-parent</artifactId>
<version>2.0.0-alpha-5-SNAPSHOT</version>
<version>2.0.0-alpha-7-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Loading