mirror of https://github.com/apache/maven.git
Restore the serializable aspect of the Model
This commit is contained in:
parent
c3361ab622
commit
49d1ec1668
|
@ -19,6 +19,7 @@ package org.apache.maven.api.model;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.AbstractSet;
|
||||
|
@ -251,7 +252,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableList<E> extends AbstractList<E> implements RandomAccess
|
||||
private abstract static class AbstractImmutableList<E>
|
||||
extends AbstractList<E>
|
||||
implements RandomAccess, Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean add( E e )
|
||||
|
@ -541,7 +544,7 @@ class ImmutableCollections
|
|||
|
||||
private static class Map1<K, V> extends AbstractImmutableMap<K, V>
|
||||
{
|
||||
private final Map.Entry<K, V> entry;
|
||||
private final Entry<K, V> entry;
|
||||
|
||||
private Map1( K key, V value )
|
||||
{
|
||||
|
@ -618,7 +621,7 @@ class ImmutableCollections
|
|||
{
|
||||
if ( index < entries.length )
|
||||
{
|
||||
return ( Map.Entry<K, V> ) entries[index++];
|
||||
return ( Entry<K, V> ) entries[index++];
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
@ -634,7 +637,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableMap<K, V> extends AbstractMap<K, V>
|
||||
private abstract static class AbstractImmutableMap<K, V>
|
||||
extends AbstractMap<K, V>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public void replaceAll( BiFunction<? super K, ? super V, ? extends V> function )
|
||||
|
@ -691,7 +696,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableSet<E> extends AbstractSet<E>
|
||||
private abstract static class AbstractImmutableSet<E>
|
||||
extends AbstractSet<E>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.api.settings;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.AbstractSet;
|
||||
|
@ -251,7 +252,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableList<E> extends AbstractList<E> implements RandomAccess
|
||||
private abstract static class AbstractImmutableList<E>
|
||||
extends AbstractList<E>
|
||||
implements RandomAccess, Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean add( E e )
|
||||
|
@ -634,7 +637,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableMap<K, V> extends AbstractMap<K, V>
|
||||
private abstract static class AbstractImmutableMap<K, V>
|
||||
extends AbstractMap<K, V>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public void replaceAll( BiFunction<? super K, ? super V, ? extends V> function )
|
||||
|
@ -691,7 +696,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableSet<E> extends AbstractSet<E>
|
||||
private abstract static class AbstractImmutableSet<E>
|
||||
extends AbstractSet<E>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.api.toolchain;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.AbstractSet;
|
||||
|
@ -251,7 +252,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableList<E> extends AbstractList<E> implements RandomAccess
|
||||
private abstract static class AbstractImmutableList<E>
|
||||
extends AbstractList<E>
|
||||
implements RandomAccess, Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean add( E e )
|
||||
|
@ -634,7 +637,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableMap<K, V> extends AbstractMap<K, V>
|
||||
private abstract static class AbstractImmutableMap<K, V>
|
||||
extends AbstractMap<K, V>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public void replaceAll( BiFunction<? super K, ? super V, ? extends V> function )
|
||||
|
@ -691,7 +696,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableSet<E> extends AbstractSet<E>
|
||||
private abstract static class AbstractImmutableSet<E>
|
||||
extends AbstractSet<E>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
|
|
|
@ -24,7 +24,8 @@ import java.io.Serializable;
|
|||
public abstract class BaseObject
|
||||
implements Serializable, Cloneable, InputLocationTracker
|
||||
{
|
||||
protected ChildrenTracking childrenTracking;
|
||||
protected transient ChildrenTracking childrenTracking;
|
||||
|
||||
protected Object delegate;
|
||||
|
||||
public BaseObject()
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package org.apache.maven.model;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class SerializationTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testModelSerialization()
|
||||
throws Exception
|
||||
{
|
||||
Model model;
|
||||
try ( InputStream is = getClass().getResourceAsStream( "/xml/pom.xml" ) )
|
||||
{
|
||||
model = new MavenXpp3Reader().read( is );
|
||||
}
|
||||
|
||||
// Serialize an inner child here so that the BaseObject.childrenTracking is non null
|
||||
Build build = model.getBuild();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try( ObjectOutputStream oos = new ObjectOutputStream( baos ) )
|
||||
{
|
||||
oos.writeObject( build );
|
||||
}
|
||||
|
||||
Build build2;
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
|
||||
try( ObjectInputStream ois = new ObjectInputStream( bais ) )
|
||||
{
|
||||
build2 = (Build) ois.readObject();
|
||||
}
|
||||
|
||||
assertNotNull( build2 );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you 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.
|
||||
-->
|
||||
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven</artifactId>
|
||||
<version>4.0.0-alpha-1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>maven-model</artifactId>
|
||||
|
||||
<name>Maven Model</name>
|
||||
<description>Model for Maven POM (Project Object Model)</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-model</artifactId>
|
||||
<version>4.0.0-alpha-1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-xml-impl</artifactId>
|
||||
<version>4.0.0-alpha-1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-model</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-api-model</artifactId>
|
||||
<version>4.0.0-alpha-1-SNAPSHOT</version>
|
||||
<type>mdo</type>
|
||||
<outputDirectory>target/mdo/</outputDirectory>
|
||||
<destFileName>maven.mdo</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>modello-plugin-velocity</artifactId>
|
||||
<version>4.0.0-alpha-1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>velocity</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>velocity</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<version>4.0.0</version>
|
||||
<models>
|
||||
<model>target/mdo/maven.mdo</model>
|
||||
</models>
|
||||
<templates>
|
||||
<template>src/main/mdo/model-v3.vm</template>
|
||||
<template>src/main/mdo/merger.vm</template>
|
||||
<template>src/main/mdo/transformer.vm</template>
|
||||
<template>src/main/mdo/reader.vm</template>
|
||||
<template>src/main/mdo/reader-ex.vm</template>
|
||||
<template>src/main/mdo/writer.vm</template>
|
||||
<template>src/main/mdo/writer-ex.vm</template>
|
||||
</templates>
|
||||
<params>
|
||||
<param>packageModelV3=org.apache.maven.model</param>
|
||||
<param>packageModelV4=org.apache.maven.api.model</param>
|
||||
<param>packageToolV4=org.apache.maven.model.v4</param>
|
||||
</params>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/package-info.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -19,6 +19,7 @@ package org.apache.maven.plugin.lifecycle;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.AbstractList;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.AbstractSet;
|
||||
|
@ -251,7 +252,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableList<E> extends AbstractList<E> implements RandomAccess
|
||||
private abstract static class AbstractImmutableList<E>
|
||||
extends AbstractList<E>
|
||||
implements RandomAccess, Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean add( E e )
|
||||
|
@ -634,7 +637,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableMap<K, V> extends AbstractMap<K, V>
|
||||
private abstract static class AbstractImmutableMap<K, V>
|
||||
extends AbstractMap<K, V>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public void replaceAll( BiFunction<? super K, ? super V, ? extends V> function )
|
||||
|
@ -691,7 +696,9 @@ class ImmutableCollections
|
|||
}
|
||||
}
|
||||
|
||||
private abstract static class AbstractImmutableSet<E> extends AbstractSet<E>
|
||||
private abstract static class AbstractImmutableSet<E>
|
||||
extends AbstractSet<E>
|
||||
implements Serializable
|
||||
{
|
||||
@Override
|
||||
public boolean removeAll( Collection<?> c )
|
||||
|
|
Loading…
Reference in New Issue