Skip to content

Commit

Permalink
Merge pull request #1531 from lukasj/backports
Browse files Browse the repository at this point in the history
Backports from master to EE8
  • Loading branch information
lukasj authored Apr 8, 2021
2 parents 4216dc7 + 9bde2cf commit 03d7370
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 23 deletions.
34 changes: 34 additions & 0 deletions jaxb-ri/boms/bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>codemodel</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>txw2</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>xsom</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>

<!--OLD-->
<dependency>
Expand Down Expand Up @@ -120,6 +138,22 @@
<artifactId>jaxb-jxc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>codemodel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>txw2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>xsom</artifactId>
<version>${project.version}</version>
</dependency>


<!--OLD-->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion jaxb-ri/runtime/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<configuration>
<workingDirectory>target/test-out</workingDirectory>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<reuseForks>false</reuseForks>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -187,6 +187,9 @@ private static <B,V> Accessor<B,V> instanciate(Class opt) {
logger.log(Level.INFO,"failed to load an optimized Accessor",e);
} catch (SecurityException e) {
logger.log(Level.INFO,"failed to load an optimized Accessor",e);
} catch (ClassCastException e) {
logger.log(Level.FINE,"failed to cast optimized Accessor " +
"created by repackaged jaxb "+opt,e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

package com.sun.xml.bind.v2.runtime.reflect.opt;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.sun.xml.bind.v2.bytecode.ClassTailor;
import com.sun.xml.bind.v2.runtime.reflect.Accessor;
import org.junit.Test;

public class ForeignAccessorTest {

/**
* Foreign accessor shouldn't throw ClassCastException, just skip optimization.
*/
@Test
public void foreignAccessor() throws NoSuchFieldException{
String newClassName = EntityWithForeignAccessor.class.getName().replace('.','/') + "$JaxbAccessorF_author";
Class<?> foreignAccessor = AccessorInjector.prepare(EntityWithForeignAccessor.class,
ClassTailor.toVMClassName(ForeignAccessorTest.FieldAccessor_Ref.class),
newClassName);
assertNotNull(foreignAccessor);

Accessor<Object, Object> accessor = OptimizedAccessorFactory.get(EntityWithForeignAccessor.class.getDeclaredField("author"));
assertNull(accessor);
}

@Test
public void knownAccessor() throws NoSuchFieldException {
Accessor<Object, Object> accessor = OptimizedAccessorFactory.get(EntityWithKnownAccessor.class.getDeclaredField("author"));
assertNotNull(accessor);
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
static class EntityWithKnownAccessor {
String author;
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
static class EntityWithForeignAccessor {
String author;
}

/**
* Test template doesn't extend accessor intentionally.
*/
public static class FieldAccessor_Ref /*extends Accessor*/ {
public FieldAccessor_Ref() {
// super(Ref.class);
}

public Object get(Object bean) {
return ((Bean)bean).f_ref;
}

public void set(Object bean, Object value) {
((Bean)bean).f_ref = (Ref)value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

package com.sun.tools.xjc.addon.at_generated;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.sun.codemodel.JAnnotatable;
import com.sun.codemodel.JAnnotationUse;
import com.sun.codemodel.JClass;
Expand All @@ -27,11 +24,13 @@
import com.sun.tools.xjc.outline.Outline;
import com.sun.tools.xjc.outline.PackageOutline;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import org.xml.sax.ErrorHandler;

/**
* {@link Plugin} that marks the generated code by using JSR-250's '@Generated'.
* {@link Plugin} that marks the generated code by using '@Generated'.
*
* @author Kohsuke Kawaguchi
* @author Lukas Jungmann
Expand Down Expand Up @@ -121,12 +120,8 @@ private void annotate(JAnnotatable m) {
*/
private String getISO8601Date() {
if(date==null) {
StringBuffer tstamp = new StringBuffer();
tstamp.append((new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ")).format(new Date()));
// hack to get ISO 8601 style timezone - is there a better way that doesn't require
// a bunch of timezone offset calculations?
tstamp.insert(tstamp.length()-2, ':');
date = tstamp.toString();
ZonedDateTime zdt = ZonedDateTime.now().withNano(0);
date = zdt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
return date;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import com.sun.xml.bind.unmarshaller.DOMScanner;
import com.sun.xml.bind.v2.util.XmlFactory;
import com.sun.xml.xsom.XSSchemaSet;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.w3c.dom.Element;
import org.w3c.dom.ls.LSInput;
Expand Down Expand Up @@ -213,8 +215,7 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
// XSOM passes the namespace URI to the publicID parameter.
// we do the same here .
InputSource is = opts.entityResolver.resolveEntity(namespaceURI, systemId == null ? "" : systemId);
if (is == null) return null;
return new LSInputSAXWrapper(is);
return isExists(is) ? new LSInputSAXWrapper(is) : null;
} catch (SAXException e) {
// TODO: is this sufficient?
return null;
Expand Down Expand Up @@ -292,6 +293,21 @@ public void fatalError(SAXParseException exception) {
errorListener.fatalError(exception);
}

private static boolean isExists(InputSource is) {
if (is == null) {
return false;
}
try {
URI uri = new URI(is.getSystemId());
if ("file".equals(uri.getScheme())) {
return Files.exists(Paths.get(uri));
}
} catch (URISyntaxException ex) {
//ignore, let it be handled by parser as is
}
return true;
}

/**
* We use JAXP 1.3 to do a schema correctness check, but we know
* it doesn't always work. So in case some people hit the problem,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -12,7 +12,9 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.xml.bind.annotation.W3CDomHandler;
import javax.xml.bind.annotation.XmlList;
Expand Down Expand Up @@ -50,6 +52,9 @@
import com.sun.tools.xjc.model.nav.NClass;
import com.sun.tools.xjc.outline.Aspect;
import static com.sun.tools.xjc.outline.Aspect.IMPLEMENTATION;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toList;

import com.sun.tools.xjc.outline.ClassOutline;
import com.sun.tools.xjc.outline.FieldAccessor;
import com.sun.tools.xjc.outline.FieldOutline;
Expand Down Expand Up @@ -453,8 +458,11 @@ void add( Collection<? extends CTypeInfo> col ) {
*/
protected final List<Object> listPossibleTypes( CPropertyInfo prop ) {
List<Object> r = new ArrayList<Object>();
for( CTypeInfo tt : prop.ref() ) {
JType t = tt.getType().toType(outline.parent(),Aspect.EXPOSED);
List<JType> refs = prop.ref().stream()
.map(tt -> tt.toType(outline.parent(), Aspect.EXPOSED))
.sorted(comparing(JType::fullName))
.collect(toList());
for( JType t : refs ) {
if( t.isPrimitive() || t.isArray() )
r.add(t.fullName());
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -43,6 +43,10 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

import static com.sun.xml.bind.v2.util.XmlFactory.allowExternalAccess;
Expand Down Expand Up @@ -263,11 +267,26 @@ public Document parse( String systemId, boolean root ) throws SAXException, IOEx
InputSource is=null;

// allow entity resolver to find the actual byte stream.
if( entityResolver!=null )
if( entityResolver!=null ) {
is = entityResolver.resolveEntity(null,systemId);
if( is==null )
}
if (is == null) {
is = new InputSource(systemId);

} else {
try {
URI uri = new URI(is.getSystemId());
if ("file".equals(uri.getScheme())) {
if (!Files.exists(Paths.get(uri))) {
//resolved file does not exist, warn and let's continue with original systemId
errorReceiver.warning(null, Messages.format(
Messages.DOMFOREST_CATALOG_INVALID_ENTRY, is.getSystemId(), systemId));
is = new InputSource(systemId);
}
}
} catch (URISyntaxException ex) {
//ignore, let it be handled by parser as is
}
}
// but we still use the original system Id as the key.
return parse( systemId, is, root );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -66,5 +66,7 @@ static String format( String property, Object... args ) {
"ERR_GENERAL_SCHEMA_CORRECTNESS_ERROR";
static final String DOMFOREST_INPUTSOURCE_IOEXCEPTION = // arg:2
"DOMFOREST_INPUTSOURCE_IOEXCEPTION";
static final String DOMFOREST_CATALOG_INVALID_ENTRY = // arg:2
"DOMFOREST_CATALOG_INVALID_ENTRY";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -88,3 +88,6 @@ ERR_FILENAME_IS_NOT_URI = \

DOMFOREST_INPUTSOURCE_IOEXCEPTION = \
IOException thrown when processing "{0}". Exception: {1}.

DOMFOREST_CATALOG_INVALID_ENTRY = \
Catalog points to non-existent resource: "{0}". Trying to reach "{1}" directly.

0 comments on commit 03d7370

Please sign in to comment.