diff --git a/api/maven-api-settings/src/main/java/org/apache/maven/api/settings/ImmutableCollections.java b/api/maven-api-settings/src/main/java/org/apache/maven/api/settings/ImmutableCollections.java deleted file mode 100644 index cf6de272d8..0000000000 --- a/api/maven-api-settings/src/main/java/org/apache/maven/api/settings/ImmutableCollections.java +++ /dev/null @@ -1,609 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.api.settings; - -import java.io.Serializable; -import java.util.AbstractList; -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.RandomAccess; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -class ImmutableCollections { - - private static final List EMPTY_LIST = new AbstractImmutableList() { - @Override - public Object get(int index) { - throw new IndexOutOfBoundsException(); - } - - @Override - public int size() { - return 0; - } - }; - - private static final Map EMPTY_MAP = new AbstractImmutableMap() { - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Entry next() { - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return 0; - } - }; - } - }; - - static List copy(Collection collection) { - if (collection == null) { - return emptyList(); - } else if (collection instanceof AbstractImmutableList) { - return (List) collection; - } else { - switch (collection.size()) { - case 0: - return emptyList(); - case 1: - return singletonList(collection.iterator().next()); - case 2: - Iterator it = collection.iterator(); - return new List2<>(it.next(), it.next()); - default: - return new ListN<>(collection); - } - } - } - - @SuppressWarnings("unchecked") - static List emptyList() { - return (List) EMPTY_LIST; - } - - static List singletonList(E element) { - return new List1<>(element); - } - - static Map copy(Map map) { - if (map == null) { - return emptyMap(); - } else if (map instanceof AbstractImmutableMap) { - return map; - } else { - switch (map.size()) { - case 0: - return emptyMap(); - case 1: - Map.Entry entry = map.entrySet().iterator().next(); - return singletonMap(entry.getKey(), entry.getValue()); - default: - return new MapN<>(map); - } - } - } - - @SuppressWarnings("unchecked") - static Map emptyMap() { - return (Map) EMPTY_MAP; - } - - static Map singletonMap(K key, V value) { - return new Map1<>(key, value); - } - - static Properties copy(Properties properties) { - if (properties instanceof ROProperties) { - return properties; - } - return new ROProperties(properties); - } - - private static class List1 extends AbstractImmutableList { - private final E element; - - private List1(E element) { - this.element = element; - } - - @Override - public E get(int index) { - if (index == 0) { - return element; - } - throw outOfBounds(index); - } - - @Override - public int size() { - return 1; - } - } - - private static class List2 extends AbstractImmutableList { - private final E element1; - private final E element2; - - private List2(E element1, E element2) { - this.element1 = element1; - this.element2 = element2; - } - - @Override - public E get(int index) { - if (index == 0) { - return element1; - } else if (index == 1) { - return element2; - } - throw outOfBounds(index); - } - - @Override - public int size() { - return 2; - } - } - - private static class ListN extends AbstractImmutableList { - private final Object[] elements; - - private ListN(Collection elements) { - this.elements = elements.toArray(); - } - - @SuppressWarnings("unchecked") - @Override - public E get(int index) { - return (E) elements[index]; - } - - @Override - public int size() { - return elements.length; - } - } - - private abstract static class AbstractImmutableList extends AbstractList - implements RandomAccess, Serializable { - @Override - public boolean add(E e) { - throw uoe(); - } - - @Override - public boolean remove(Object o) { - throw uoe(); - } - - @Override - public boolean addAll(Collection c) { - throw uoe(); - } - - @Override - public boolean removeAll(Collection c) { - throw uoe(); - } - - @Override - public boolean retainAll(Collection c) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public boolean removeIf(Predicate filter) { - throw uoe(); - } - - @Override - public void replaceAll(UnaryOperator operator) { - throw uoe(); - } - - @Override - public void sort(Comparator c) { - throw uoe(); - } - - @Override - public Iterator iterator() { - return new Itr(0); - } - - @Override - public ListIterator listIterator() { - return new Itr(0); - } - - @Override - public ListIterator listIterator(int index) { - if (index < 0 || index > size()) { - throw outOfBounds(index); - } - return new Itr(index); - } - - @Override - public List subList(int fromIndex, int toIndex) { - if (fromIndex < 0) { - throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); - } - if (toIndex > size()) { - throw new IndexOutOfBoundsException("toIndex = " + toIndex); - } - if (fromIndex > toIndex) { - throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); - } - return new SubList(fromIndex, toIndex); - } - - protected IndexOutOfBoundsException outOfBounds(int index) { - return new IndexOutOfBoundsException("Index: " + index + ", Size: " + size()); - } - - private class SubList extends AbstractImmutableList { - private final int fromIndex; - private final int toIndex; - - private SubList(int fromIndex, int toIndex) { - this.fromIndex = fromIndex; - this.toIndex = toIndex; - } - - @Override - public E get(int index) { - if (index < 0 || index > size()) { - throw outOfBounds(index); - } - return AbstractImmutableList.this.get(fromIndex + index); - } - - @Override - public int size() { - return toIndex - fromIndex; - } - } - - private class Itr implements ListIterator { - int index; - - private Itr(int index) { - this.index = index; - } - - @Override - public boolean hasNext() { - return index < size(); - } - - @Override - public E next() { - return get(index++); - } - - @Override - public boolean hasPrevious() { - return index > 0; - } - - @Override - public E previous() { - return get(--index); - } - - @Override - public int nextIndex() { - return index; - } - - @Override - public int previousIndex() { - return index - 1; - } - - @Override - public void remove() { - throw uoe(); - } - - @Override - public void set(E e) { - throw uoe(); - } - - @Override - public void add(E e) { - throw uoe(); - } - } - } - - private static class ROProperties extends Properties { - private ROProperties(Properties props) { - super(); - if (props != null) { - // Do not use super.putAll, as it may delegate to put which throws an UnsupportedOperationException - for (Map.Entry e : props.entrySet()) { - super.put(e.getKey(), e.getValue()); - } - } - } - - @Override - public Object put(Object key, Object value) { - throw uoe(); - } - - @Override - public Object remove(Object key) { - throw uoe(); - } - - @Override - public void putAll(Map t) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public void replaceAll(BiFunction function) { - throw uoe(); - } - - @Override - public Object putIfAbsent(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean remove(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean replace(Object key, Object oldValue, Object newValue) { - throw uoe(); - } - - @Override - public Object replace(Object key, Object value) { - throw uoe(); - } - - @Override - public Object computeIfAbsent(Object key, Function mappingFunction) { - throw uoe(); - } - - @Override - public Object computeIfPresent(Object key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public Object compute(Object key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public Object merge(Object key, Object value, BiFunction remappingFunction) { - throw uoe(); - } - } - - private static class Map1 extends AbstractImmutableMap { - private final Entry entry; - - private Map1(K key, V value) { - this.entry = new SimpleImmutableEntry<>(key, value); - } - - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - int index = 0; - - @Override - public boolean hasNext() { - return index == 0; - } - - @Override - public Entry next() { - if (index++ == 0) { - return entry; - } - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return 1; - } - }; - } - } - - private static class MapN extends AbstractImmutableMap { - private final Object[] entries; - - private MapN(Map map) { - entries = map != null - ? map.entrySet().stream() - .map(e -> new SimpleImmutableEntry<>(e.getKey(), e.getValue())) - .toArray() - : new Object[0]; - } - - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - int index = 0; - - @Override - public boolean hasNext() { - return index < entries.length; - } - - @SuppressWarnings("unchecked") - @Override - public Entry next() { - if (index < entries.length) { - return (Entry) entries[index++]; - } - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return entries.length; - } - }; - } - } - - private abstract static class AbstractImmutableMap extends AbstractMap implements Serializable { - @Override - public void replaceAll(BiFunction function) { - throw uoe(); - } - - @Override - public V putIfAbsent(K key, V value) { - throw uoe(); - } - - @Override - public boolean remove(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean replace(K key, V oldValue, V newValue) { - throw uoe(); - } - - @Override - public V replace(K key, V value) { - throw uoe(); - } - - @Override - public V computeIfAbsent(K key, Function mappingFunction) { - throw uoe(); - } - - @Override - public V computeIfPresent(K key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public V compute(K key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public V merge(K key, V value, BiFunction remappingFunction) { - throw uoe(); - } - } - - private abstract static class AbstractImmutableSet extends AbstractSet implements Serializable { - @Override - public boolean removeAll(Collection c) { - throw uoe(); - } - - @Override - public boolean add(E e) { - throw uoe(); - } - - @Override - public boolean remove(Object o) { - throw uoe(); - } - - @Override - public boolean retainAll(Collection c) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public boolean removeIf(Predicate filter) { - throw uoe(); - } - } - - private static UnsupportedOperationException uoe() { - return new UnsupportedOperationException(); - } -} diff --git a/api/maven-api-toolchain/src/main/java/org/apache/maven/api/toolchain/ImmutableCollections.java b/api/maven-api-toolchain/src/main/java/org/apache/maven/api/toolchain/ImmutableCollections.java deleted file mode 100644 index 5fa99017e8..0000000000 --- a/api/maven-api-toolchain/src/main/java/org/apache/maven/api/toolchain/ImmutableCollections.java +++ /dev/null @@ -1,609 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.api.toolchain; - -import java.io.Serializable; -import java.util.AbstractList; -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.RandomAccess; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -class ImmutableCollections { - - private static final List EMPTY_LIST = new AbstractImmutableList() { - @Override - public Object get(int index) { - throw new IndexOutOfBoundsException(); - } - - @Override - public int size() { - return 0; - } - }; - - private static final Map EMPTY_MAP = new AbstractImmutableMap() { - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Entry next() { - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return 0; - } - }; - } - }; - - static List copy(Collection collection) { - if (collection == null) { - return emptyList(); - } else if (collection instanceof AbstractImmutableList) { - return (List) collection; - } else { - switch (collection.size()) { - case 0: - return emptyList(); - case 1: - return singletonList(collection.iterator().next()); - case 2: - Iterator it = collection.iterator(); - return new List2<>(it.next(), it.next()); - default: - return new ListN<>(collection); - } - } - } - - @SuppressWarnings("unchecked") - static List emptyList() { - return (List) EMPTY_LIST; - } - - static List singletonList(E element) { - return new List1<>(element); - } - - static Map copy(Map map) { - if (map == null) { - return emptyMap(); - } else if (map instanceof AbstractImmutableMap) { - return map; - } else { - switch (map.size()) { - case 0: - return emptyMap(); - case 1: - Map.Entry entry = map.entrySet().iterator().next(); - return singletonMap(entry.getKey(), entry.getValue()); - default: - return new MapN<>(map); - } - } - } - - @SuppressWarnings("unchecked") - static Map emptyMap() { - return (Map) EMPTY_MAP; - } - - static Map singletonMap(K key, V value) { - return new Map1<>(key, value); - } - - static Properties copy(Properties properties) { - if (properties instanceof ROProperties) { - return properties; - } - return new ROProperties(properties); - } - - private static class List1 extends AbstractImmutableList { - private final E element; - - private List1(E element) { - this.element = element; - } - - @Override - public E get(int index) { - if (index == 0) { - return element; - } - throw outOfBounds(index); - } - - @Override - public int size() { - return 1; - } - } - - private static class List2 extends AbstractImmutableList { - private final E element1; - private final E element2; - - private List2(E element1, E element2) { - this.element1 = element1; - this.element2 = element2; - } - - @Override - public E get(int index) { - if (index == 0) { - return element1; - } else if (index == 1) { - return element2; - } - throw outOfBounds(index); - } - - @Override - public int size() { - return 2; - } - } - - private static class ListN extends AbstractImmutableList { - private final Object[] elements; - - private ListN(Collection elements) { - this.elements = elements.toArray(); - } - - @SuppressWarnings("unchecked") - @Override - public E get(int index) { - return (E) elements[index]; - } - - @Override - public int size() { - return elements.length; - } - } - - private abstract static class AbstractImmutableList extends AbstractList - implements RandomAccess, Serializable { - @Override - public boolean add(E e) { - throw uoe(); - } - - @Override - public boolean remove(Object o) { - throw uoe(); - } - - @Override - public boolean addAll(Collection c) { - throw uoe(); - } - - @Override - public boolean removeAll(Collection c) { - throw uoe(); - } - - @Override - public boolean retainAll(Collection c) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public boolean removeIf(Predicate filter) { - throw uoe(); - } - - @Override - public void replaceAll(UnaryOperator operator) { - throw uoe(); - } - - @Override - public void sort(Comparator c) { - throw uoe(); - } - - @Override - public Iterator iterator() { - return new Itr(0); - } - - @Override - public ListIterator listIterator() { - return new Itr(0); - } - - @Override - public ListIterator listIterator(int index) { - if (index < 0 || index > size()) { - throw outOfBounds(index); - } - return new Itr(index); - } - - @Override - public List subList(int fromIndex, int toIndex) { - if (fromIndex < 0) { - throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); - } - if (toIndex > size()) { - throw new IndexOutOfBoundsException("toIndex = " + toIndex); - } - if (fromIndex > toIndex) { - throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); - } - return new SubList(fromIndex, toIndex); - } - - protected IndexOutOfBoundsException outOfBounds(int index) { - return new IndexOutOfBoundsException("Index: " + index + ", Size: " + size()); - } - - private class SubList extends AbstractImmutableList { - private final int fromIndex; - private final int toIndex; - - private SubList(int fromIndex, int toIndex) { - this.fromIndex = fromIndex; - this.toIndex = toIndex; - } - - @Override - public E get(int index) { - if (index < 0 || index > size()) { - throw outOfBounds(index); - } - return AbstractImmutableList.this.get(fromIndex + index); - } - - @Override - public int size() { - return toIndex - fromIndex; - } - } - - private class Itr implements ListIterator { - int index; - - private Itr(int index) { - this.index = index; - } - - @Override - public boolean hasNext() { - return index < size(); - } - - @Override - public E next() { - return get(index++); - } - - @Override - public boolean hasPrevious() { - return index > 0; - } - - @Override - public E previous() { - return get(--index); - } - - @Override - public int nextIndex() { - return index; - } - - @Override - public int previousIndex() { - return index - 1; - } - - @Override - public void remove() { - throw uoe(); - } - - @Override - public void set(E e) { - throw uoe(); - } - - @Override - public void add(E e) { - throw uoe(); - } - } - } - - private static class ROProperties extends Properties { - private ROProperties(Properties props) { - super(); - if (props != null) { - // Do not use super.putAll, as it may delegate to put which throws an UnsupportedOperationException - for (Map.Entry e : props.entrySet()) { - super.put(e.getKey(), e.getValue()); - } - } - } - - @Override - public Object put(Object key, Object value) { - throw uoe(); - } - - @Override - public Object remove(Object key) { - throw uoe(); - } - - @Override - public void putAll(Map t) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public void replaceAll(BiFunction function) { - throw uoe(); - } - - @Override - public Object putIfAbsent(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean remove(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean replace(Object key, Object oldValue, Object newValue) { - throw uoe(); - } - - @Override - public Object replace(Object key, Object value) { - throw uoe(); - } - - @Override - public Object computeIfAbsent(Object key, Function mappingFunction) { - throw uoe(); - } - - @Override - public Object computeIfPresent(Object key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public Object compute(Object key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public Object merge(Object key, Object value, BiFunction remappingFunction) { - throw uoe(); - } - } - - private static class Map1 extends AbstractImmutableMap { - private final Entry entry; - - private Map1(K key, V value) { - this.entry = new SimpleImmutableEntry<>(key, value); - } - - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - int index = 0; - - @Override - public boolean hasNext() { - return index == 0; - } - - @Override - public Entry next() { - if (index++ == 0) { - return entry; - } - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return 1; - } - }; - } - } - - private static class MapN extends AbstractImmutableMap { - private final Object[] entries; - - private MapN(Map map) { - entries = map != null - ? map.entrySet().stream() - .map(e -> new SimpleImmutableEntry<>(e.getKey(), e.getValue())) - .toArray() - : new Object[0]; - } - - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - int index = 0; - - @Override - public boolean hasNext() { - return index < entries.length; - } - - @SuppressWarnings("unchecked") - @Override - public Entry next() { - if (index < entries.length) { - return (Entry) entries[index++]; - } - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return entries.length; - } - }; - } - } - - private abstract static class AbstractImmutableMap extends AbstractMap implements Serializable { - @Override - public void replaceAll(BiFunction function) { - throw uoe(); - } - - @Override - public V putIfAbsent(K key, V value) { - throw uoe(); - } - - @Override - public boolean remove(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean replace(K key, V oldValue, V newValue) { - throw uoe(); - } - - @Override - public V replace(K key, V value) { - throw uoe(); - } - - @Override - public V computeIfAbsent(K key, Function mappingFunction) { - throw uoe(); - } - - @Override - public V computeIfPresent(K key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public V compute(K key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public V merge(K key, V value, BiFunction remappingFunction) { - throw uoe(); - } - } - - private abstract static class AbstractImmutableSet extends AbstractSet implements Serializable { - @Override - public boolean removeAll(Collection c) { - throw uoe(); - } - - @Override - public boolean add(E e) { - throw uoe(); - } - - @Override - public boolean remove(Object o) { - throw uoe(); - } - - @Override - public boolean retainAll(Collection c) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public boolean removeIf(Predicate filter) { - throw uoe(); - } - } - - private static UnsupportedOperationException uoe() { - return new UnsupportedOperationException(); - } -} diff --git a/maven-plugin-api/src/main/java/org/apache/maven/plugin/lifecycle/ImmutableCollections.java b/maven-plugin-api/src/main/java/org/apache/maven/plugin/lifecycle/ImmutableCollections.java deleted file mode 100644 index 405edc3f02..0000000000 --- a/maven-plugin-api/src/main/java/org/apache/maven/plugin/lifecycle/ImmutableCollections.java +++ /dev/null @@ -1,609 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.plugin.lifecycle; - -import java.io.Serializable; -import java.util.AbstractList; -import java.util.AbstractMap; -import java.util.AbstractSet; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.RandomAccess; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.UnaryOperator; - -class ImmutableCollections { - - private static final List EMPTY_LIST = new AbstractImmutableList() { - @Override - public Object get(int index) { - throw new IndexOutOfBoundsException(); - } - - @Override - public int size() { - return 0; - } - }; - - private static final Map EMPTY_MAP = new AbstractImmutableMap() { - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - @Override - public boolean hasNext() { - return false; - } - - @Override - public Entry next() { - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return 0; - } - }; - } - }; - - static List copy(Collection collection) { - if (collection == null) { - return emptyList(); - } else if (collection instanceof AbstractImmutableList) { - return (List) collection; - } else { - switch (collection.size()) { - case 0: - return emptyList(); - case 1: - return singletonList(collection.iterator().next()); - case 2: - Iterator it = collection.iterator(); - return new List2<>(it.next(), it.next()); - default: - return new ListN<>(collection); - } - } - } - - @SuppressWarnings("unchecked") - static List emptyList() { - return (List) EMPTY_LIST; - } - - static List singletonList(E element) { - return new List1<>(element); - } - - static Map copy(Map map) { - if (map == null) { - return emptyMap(); - } else if (map instanceof AbstractImmutableMap) { - return map; - } else { - switch (map.size()) { - case 0: - return emptyMap(); - case 1: - Map.Entry entry = map.entrySet().iterator().next(); - return singletonMap(entry.getKey(), entry.getValue()); - default: - return new MapN<>(map); - } - } - } - - @SuppressWarnings("unchecked") - static Map emptyMap() { - return (Map) EMPTY_MAP; - } - - static Map singletonMap(K key, V value) { - return new Map1<>(key, value); - } - - static Properties copy(Properties properties) { - if (properties instanceof ROProperties) { - return properties; - } - return new ROProperties(properties); - } - - private static class List1 extends AbstractImmutableList { - private final E element; - - private List1(E element) { - this.element = element; - } - - @Override - public E get(int index) { - if (index == 0) { - return element; - } - throw outOfBounds(index); - } - - @Override - public int size() { - return 1; - } - } - - private static class List2 extends AbstractImmutableList { - private final E element1; - private final E element2; - - private List2(E element1, E element2) { - this.element1 = element1; - this.element2 = element2; - } - - @Override - public E get(int index) { - if (index == 0) { - return element1; - } else if (index == 1) { - return element2; - } - throw outOfBounds(index); - } - - @Override - public int size() { - return 2; - } - } - - private static class ListN extends AbstractImmutableList { - private final Object[] elements; - - private ListN(Collection elements) { - this.elements = elements.toArray(); - } - - @SuppressWarnings("unchecked") - @Override - public E get(int index) { - return (E) elements[index]; - } - - @Override - public int size() { - return elements.length; - } - } - - private abstract static class AbstractImmutableList extends AbstractList - implements RandomAccess, Serializable { - @Override - public boolean add(E e) { - throw uoe(); - } - - @Override - public boolean remove(Object o) { - throw uoe(); - } - - @Override - public boolean addAll(Collection c) { - throw uoe(); - } - - @Override - public boolean removeAll(Collection c) { - throw uoe(); - } - - @Override - public boolean retainAll(Collection c) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public boolean removeIf(Predicate filter) { - throw uoe(); - } - - @Override - public void replaceAll(UnaryOperator operator) { - throw uoe(); - } - - @Override - public void sort(Comparator c) { - throw uoe(); - } - - @Override - public Iterator iterator() { - return new Itr(0); - } - - @Override - public ListIterator listIterator() { - return new Itr(0); - } - - @Override - public ListIterator listIterator(int index) { - if (index < 0 || index > size()) { - throw outOfBounds(index); - } - return new Itr(index); - } - - @Override - public List subList(int fromIndex, int toIndex) { - if (fromIndex < 0) { - throw new IndexOutOfBoundsException("fromIndex = " + fromIndex); - } - if (toIndex > size()) { - throw new IndexOutOfBoundsException("toIndex = " + toIndex); - } - if (fromIndex > toIndex) { - throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")"); - } - return new SubList(fromIndex, toIndex); - } - - protected IndexOutOfBoundsException outOfBounds(int index) { - return new IndexOutOfBoundsException("Index: " + index + ", Size: " + size()); - } - - private class SubList extends AbstractImmutableList { - private final int fromIndex; - private final int toIndex; - - private SubList(int fromIndex, int toIndex) { - this.fromIndex = fromIndex; - this.toIndex = toIndex; - } - - @Override - public E get(int index) { - if (index < 0 || index > size()) { - throw outOfBounds(index); - } - return AbstractImmutableList.this.get(fromIndex + index); - } - - @Override - public int size() { - return toIndex - fromIndex; - } - } - - private class Itr implements ListIterator { - int index; - - private Itr(int index) { - this.index = index; - } - - @Override - public boolean hasNext() { - return index < size(); - } - - @Override - public E next() { - return get(index++); - } - - @Override - public boolean hasPrevious() { - return index > 0; - } - - @Override - public E previous() { - return get(--index); - } - - @Override - public int nextIndex() { - return index; - } - - @Override - public int previousIndex() { - return index - 1; - } - - @Override - public void remove() { - throw uoe(); - } - - @Override - public void set(E e) { - throw uoe(); - } - - @Override - public void add(E e) { - throw uoe(); - } - } - } - - private static class ROProperties extends Properties { - private ROProperties(Properties props) { - super(); - if (props != null) { - // Do not use super.putAll, as it may delegate to put which throws an UnsupportedOperationException - for (Map.Entry e : props.entrySet()) { - super.put(e.getKey(), e.getValue()); - } - } - } - - @Override - public Object put(Object key, Object value) { - throw uoe(); - } - - @Override - public Object remove(Object key) { - throw uoe(); - } - - @Override - public void putAll(Map t) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public void replaceAll(BiFunction function) { - throw uoe(); - } - - @Override - public Object putIfAbsent(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean remove(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean replace(Object key, Object oldValue, Object newValue) { - throw uoe(); - } - - @Override - public Object replace(Object key, Object value) { - throw uoe(); - } - - @Override - public Object computeIfAbsent(Object key, Function mappingFunction) { - throw uoe(); - } - - @Override - public Object computeIfPresent(Object key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public Object compute(Object key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public Object merge(Object key, Object value, BiFunction remappingFunction) { - throw uoe(); - } - } - - private static class Map1 extends AbstractImmutableMap { - private final Entry entry; - - private Map1(K key, V value) { - this.entry = new SimpleImmutableEntry<>(key, value); - } - - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - int index = 0; - - @Override - public boolean hasNext() { - return index == 0; - } - - @Override - public Entry next() { - if (index++ == 0) { - return entry; - } - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return 1; - } - }; - } - } - - private static class MapN extends AbstractImmutableMap { - private final Object[] entries; - - private MapN(Map map) { - entries = map != null - ? map.entrySet().stream() - .map(e -> new SimpleImmutableEntry<>(e.getKey(), e.getValue())) - .toArray() - : new Object[0]; - } - - @Override - public Set> entrySet() { - return new AbstractImmutableSet>() { - @Override - public Iterator> iterator() { - return new Iterator>() { - int index = 0; - - @Override - public boolean hasNext() { - return index < entries.length; - } - - @SuppressWarnings("unchecked") - @Override - public Entry next() { - if (index < entries.length) { - return (Entry) entries[index++]; - } - throw new NoSuchElementException(); - } - }; - } - - @Override - public int size() { - return entries.length; - } - }; - } - } - - private abstract static class AbstractImmutableMap extends AbstractMap implements Serializable { - @Override - public void replaceAll(BiFunction function) { - throw uoe(); - } - - @Override - public V putIfAbsent(K key, V value) { - throw uoe(); - } - - @Override - public boolean remove(Object key, Object value) { - throw uoe(); - } - - @Override - public boolean replace(K key, V oldValue, V newValue) { - throw uoe(); - } - - @Override - public V replace(K key, V value) { - throw uoe(); - } - - @Override - public V computeIfAbsent(K key, Function mappingFunction) { - throw uoe(); - } - - @Override - public V computeIfPresent(K key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public V compute(K key, BiFunction remappingFunction) { - throw uoe(); - } - - @Override - public V merge(K key, V value, BiFunction remappingFunction) { - throw uoe(); - } - } - - private abstract static class AbstractImmutableSet extends AbstractSet implements Serializable { - @Override - public boolean removeAll(Collection c) { - throw uoe(); - } - - @Override - public boolean add(E e) { - throw uoe(); - } - - @Override - public boolean remove(Object o) { - throw uoe(); - } - - @Override - public boolean retainAll(Collection c) { - throw uoe(); - } - - @Override - public void clear() { - throw uoe(); - } - - @Override - public boolean removeIf(Predicate filter) { - throw uoe(); - } - } - - private static UnsupportedOperationException uoe() { - return new UnsupportedOperationException(); - } -} diff --git a/maven-settings/src/main/java/org/apache/maven/settings/WrapperList.java b/maven-settings/src/main/java/org/apache/maven/settings/WrapperList.java deleted file mode 100644 index 7da5d6cb82..0000000000 --- a/maven-settings/src/main/java/org/apache/maven/settings/WrapperList.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.settings; - -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -class WrapperList extends AbstractList { - private final Supplier> getter; - private final Consumer> setter; - private final Function mapper; - private final Function revMapper; - - WrapperList(List list, Function mapper, Function revMapper) { - this(() -> list, null, mapper, revMapper); - } - - WrapperList(Supplier> getter, Consumer> setter, Function mapper, Function revMapper) { - this.getter = getter; - this.setter = setter; - this.mapper = mapper; - this.revMapper = revMapper; - } - - @Override - public T get(int index) { - return mapper.apply(getter.get().get(index)); - } - - @Override - public int size() { - return getter.get().size(); - } - - @Override - public boolean add(T t) { - Objects.requireNonNull(t); - if (setter != null) { - List list = new ArrayList<>(getter.get()); - boolean ret = list.add(revMapper.apply(t)); - setter.accept(list); - return ret; - } else { - return getter.get().add(revMapper.apply(t)); - } - } - - @Override - public T set(int index, T element) { - Objects.requireNonNull(element); - if (setter != null) { - List list = new ArrayList<>(getter.get()); - U ret = list.set(index, revMapper.apply(element)); - setter.accept(list); - return mapper.apply(ret); - } else { - return mapper.apply(getter.get().set(index, revMapper.apply(element))); - } - } - - @Override - public void add(int index, T element) { - Objects.requireNonNull(element); - if (setter != null) { - List list = new ArrayList<>(getter.get()); - list.add(index, revMapper.apply(element)); - setter.accept(list); - } else { - getter.get().add(index, revMapper.apply(element)); - } - } - - @Override - public T remove(int index) { - if (setter != null) { - List list = new ArrayList<>(getter.get()); - U ret = list.remove(index); - setter.accept(list); - return mapper.apply(ret); - } else { - return mapper.apply(getter.get().remove(index)); - } - } -} diff --git a/maven-settings/src/main/java/org/apache/maven/settings/WrapperProperties.java b/maven-settings/src/main/java/org/apache/maven/settings/WrapperProperties.java deleted file mode 100644 index e74d053f86..0000000000 --- a/maven-settings/src/main/java/org/apache/maven/settings/WrapperProperties.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.settings; - -import java.io.IOError; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.InvalidPropertiesFormatException; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -class WrapperProperties extends Properties { - - final Supplier> getter; - final Consumer setter; - - WrapperProperties(Supplier> getter, Consumer setter) { - this.getter = getter; - this.setter = setter; - } - - @Override - public String getProperty(String key) { - return getter.get().get(key); - } - - @Override - public String getProperty(String key, String defaultValue) { - return getter.get().getOrDefault(key, defaultValue); - } - - @Override - public Enumeration propertyNames() { - return Collections.enumeration(getter.get().keySet()); - } - - @Override - public Set stringPropertyNames() { - return getter.get().keySet(); - } - - @Override - public void list(PrintStream out) { - throw new UnsupportedOperationException(); - } - - @Override - public void list(PrintWriter out) { - throw new UnsupportedOperationException(); - } - - @Override - public int size() { - return getter.get().size(); - } - - @Override - public boolean isEmpty() { - return getter.get().isEmpty(); - } - - @Override - public Enumeration keys() { - return Collections.enumeration((Set) getter.get().keySet()); - } - - @Override - public Enumeration elements() { - return Collections.enumeration((Collection) getter.get().values()); - } - - @Override - public boolean contains(Object value) { - return getter.get().containsKey(value != null ? value.toString() : null); - } - - @Override - public boolean containsValue(Object value) { - return getter.get().containsValue(value); - } - - @Override - public boolean containsKey(Object key) { - return getter.get().containsKey(key); - } - - @Override - public Object get(Object key) { - return getter.get().get(key); - } - - @Override - public synchronized String toString() { - return getter.get().toString(); - } - - @Override - public Set keySet() { - return (Set) getter.get().keySet(); - } - - @Override - public Collection values() { - return (Collection) getter.get().values(); - } - - @Override - public Set> entrySet() { - return (Set) getter.get().entrySet(); - } - - @Override - public synchronized boolean equals(Object o) { - if (o instanceof WrapperProperties) { - o = ((WrapperProperties) o).getter.get(); - } - return getter.get().equals(o); - } - - @Override - public synchronized int hashCode() { - return getter.get().hashCode(); - } - - @Override - public Object getOrDefault(Object key, Object defaultValue) { - return getter.get().getOrDefault(key, defaultValue != null ? defaultValue.toString() : null); - } - - @Override - public synchronized void forEach(BiConsumer action) { - getter.get().forEach(action); - } - - interface WriteOp { - T perform(Properties props); - } - - interface WriteOpVoid { - void perform(Properties props); - } - - private T writeOperation(WriteOp runner) { - Properties props = new Properties(); - props.putAll(getter.get()); - T ret = runner.perform(props); - if (!props.equals(getter.get())) { - setter.accept(props); - } - return ret; - } - - private void writeOperationVoid(WriteOpVoid runner) { - Properties props = new Properties(); - props.putAll(getter.get()); - runner.perform(props); - if (!props.equals(getter.get())) { - setter.accept(props); - } - } - - @Override - public synchronized Object setProperty(String key, String value) { - return writeOperation(p -> p.setProperty(key, value)); - } - - @Override - public synchronized Object put(Object key, Object value) { - return writeOperation(p -> p.put(key, value)); - } - - @Override - public synchronized Object remove(Object key) { - return writeOperation(p -> p.remove(key)); - } - - @Override - public synchronized void putAll(Map t) { - writeOperationVoid(p -> p.putAll(t)); - } - - @Override - public synchronized void clear() { - writeOperationVoid(Properties::clear); - } - - @Override - public synchronized void replaceAll(BiFunction function) { - writeOperationVoid(p -> p.replaceAll(function)); - } - - @Override - public synchronized Object putIfAbsent(Object key, Object value) { - return writeOperation(p -> p.putIfAbsent(key, value)); - } - - @Override - public synchronized boolean remove(Object key, Object value) { - return writeOperation(p -> p.remove(key, value)); - } - - @Override - public synchronized boolean replace(Object key, Object oldValue, Object newValue) { - return writeOperation(p -> p.replace(key, oldValue, newValue)); - } - - @Override - public synchronized Object replace(Object key, Object value) { - return writeOperation(p -> p.replace(key, value)); - } - - @Override - public synchronized Object computeIfAbsent(Object key, Function mappingFunction) { - return writeOperation(p -> p.computeIfAbsent(key, mappingFunction)); - } - - @Override - public synchronized Object computeIfPresent( - Object key, BiFunction remappingFunction) { - return writeOperation(p -> p.computeIfPresent(key, remappingFunction)); - } - - @Override - public synchronized Object compute(Object key, BiFunction remappingFunction) { - return writeOperation(p -> p.compute(key, remappingFunction)); - } - - @Override - public synchronized Object merge( - Object key, Object value, BiFunction remappingFunction) { - return writeOperation(p -> p.merge(key, value, remappingFunction)); - } - - @Override - public synchronized void load(Reader reader) throws IOException { - try { - writeOperationVoid(p -> { - try { - p.load(reader); - } catch (IOException e) { - throw new IOError(e); - } - }); - } catch (IOError e) { - throw (IOException) e.getCause(); - } - } - - @Override - public synchronized void load(InputStream inStream) throws IOException { - try { - writeOperationVoid(p -> { - try { - p.load(inStream); - } catch (IOException e) { - throw new IOError(e); - } - }); - } catch (IOError e) { - throw (IOException) e.getCause(); - } - } - - @Override - public void save(OutputStream out, String comments) { - Properties props = new Properties(); - props.putAll(getter.get()); - props.save(out, comments); - } - - @Override - public void store(Writer writer, String comments) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.store(writer, comments); - } - - @Override - public void store(OutputStream out, String comments) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.store(out, comments); - } - - @Override - public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException { - throw new UnsupportedOperationException(); - } - - @Override - public void storeToXML(OutputStream os, String comment) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.storeToXML(os, comment); - } - - @Override - public void storeToXML(OutputStream os, String comment, String encoding) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.storeToXML(os, comment, encoding); - } -} diff --git a/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/WrapperList.java b/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/WrapperList.java deleted file mode 100644 index dde70036c1..0000000000 --- a/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/WrapperList.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.toolchain.model; - -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -class WrapperList extends AbstractList { - private final Supplier> getter; - private final Consumer> setter; - private final Function mapper; - private final Function revMapper; - - WrapperList(List list, Function mapper, Function revMapper) { - this(() -> list, null, mapper, revMapper); - } - - WrapperList(Supplier> getter, Consumer> setter, Function mapper, Function revMapper) { - this.getter = getter; - this.setter = setter; - this.mapper = mapper; - this.revMapper = revMapper; - } - - @Override - public T get(int index) { - return mapper.apply(getter.get().get(index)); - } - - @Override - public int size() { - return getter.get().size(); - } - - @Override - public boolean add(T t) { - Objects.requireNonNull(t); - if (setter != null) { - List list = new ArrayList<>(getter.get()); - boolean ret = list.add(revMapper.apply(t)); - setter.accept(list); - return ret; - } else { - return getter.get().add(revMapper.apply(t)); - } - } - - @Override - public T set(int index, T element) { - Objects.requireNonNull(element); - if (setter != null) { - List list = new ArrayList<>(getter.get()); - U ret = list.set(index, revMapper.apply(element)); - setter.accept(list); - return mapper.apply(ret); - } else { - return mapper.apply(getter.get().set(index, revMapper.apply(element))); - } - } - - @Override - public void add(int index, T element) { - Objects.requireNonNull(element); - if (setter != null) { - List list = new ArrayList<>(getter.get()); - list.add(index, revMapper.apply(element)); - setter.accept(list); - } else { - getter.get().add(index, revMapper.apply(element)); - } - } - - @Override - public T remove(int index) { - if (setter != null) { - List list = new ArrayList<>(getter.get()); - U ret = list.remove(index); - setter.accept(list); - return mapper.apply(ret); - } else { - return mapper.apply(getter.get().remove(index)); - } - } -} diff --git a/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/WrapperProperties.java b/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/WrapperProperties.java deleted file mode 100644 index de26f088c9..0000000000 --- a/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/WrapperProperties.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * 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. - */ -package org.apache.maven.toolchain.model; - -import java.io.IOError; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.InvalidPropertiesFormatException; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -class WrapperProperties extends Properties { - - final Supplier> getter; - final Consumer setter; - - WrapperProperties(Supplier> getter, Consumer setter) { - this.getter = getter; - this.setter = setter; - } - - @Override - public String getProperty(String key) { - return getter.get().get(key); - } - - @Override - public String getProperty(String key, String defaultValue) { - return getter.get().getOrDefault(key, defaultValue); - } - - @Override - public Enumeration propertyNames() { - return Collections.enumeration(getter.get().keySet()); - } - - @Override - public Set stringPropertyNames() { - return getter.get().keySet(); - } - - @Override - public void list(PrintStream out) { - throw new UnsupportedOperationException(); - } - - @Override - public void list(PrintWriter out) { - throw new UnsupportedOperationException(); - } - - @Override - public int size() { - return getter.get().size(); - } - - @Override - public boolean isEmpty() { - return getter.get().isEmpty(); - } - - @Override - public Enumeration keys() { - return Collections.enumeration((Set) getter.get().keySet()); - } - - @Override - public Enumeration elements() { - return Collections.enumeration((Collection) getter.get().values()); - } - - @Override - public boolean contains(Object value) { - return getter.get().containsKey(value != null ? value.toString() : null); - } - - @Override - public boolean containsValue(Object value) { - return getter.get().containsValue(value); - } - - @Override - public boolean containsKey(Object key) { - return getter.get().containsKey(key); - } - - @Override - public Object get(Object key) { - return getter.get().get(key); - } - - @Override - public synchronized String toString() { - return getter.get().toString(); - } - - @Override - public Set keySet() { - return (Set) getter.get().keySet(); - } - - @Override - public Collection values() { - return (Collection) getter.get().values(); - } - - @Override - public Set> entrySet() { - return (Set) getter.get().entrySet(); - } - - @Override - public synchronized boolean equals(Object o) { - if (o instanceof WrapperProperties) { - o = ((WrapperProperties) o).getter.get(); - } - return getter.get().equals(o); - } - - @Override - public synchronized int hashCode() { - return getter.get().hashCode(); - } - - @Override - public Object getOrDefault(Object key, Object defaultValue) { - return getter.get().getOrDefault(key, defaultValue != null ? defaultValue.toString() : null); - } - - @Override - public synchronized void forEach(BiConsumer action) { - getter.get().forEach(action); - } - - interface WriteOp { - T perform(Properties props); - } - - interface WriteOpVoid { - void perform(Properties props); - } - - private T writeOperation(WriteOp runner) { - Properties props = new Properties(); - props.putAll(getter.get()); - T ret = runner.perform(props); - if (!props.equals(getter.get())) { - setter.accept(props); - } - return ret; - } - - private void writeOperationVoid(WriteOpVoid runner) { - Properties props = new Properties(); - props.putAll(getter.get()); - runner.perform(props); - if (!props.equals(getter.get())) { - setter.accept(props); - } - } - - @Override - public synchronized Object setProperty(String key, String value) { - return writeOperation(p -> p.setProperty(key, value)); - } - - @Override - public synchronized Object put(Object key, Object value) { - return writeOperation(p -> p.put(key, value)); - } - - @Override - public synchronized Object remove(Object key) { - return writeOperation(p -> p.remove(key)); - } - - @Override - public synchronized void putAll(Map t) { - writeOperationVoid(p -> p.putAll(t)); - } - - @Override - public synchronized void clear() { - writeOperationVoid(Properties::clear); - } - - @Override - public synchronized void replaceAll(BiFunction function) { - writeOperationVoid(p -> p.replaceAll(function)); - } - - @Override - public synchronized Object putIfAbsent(Object key, Object value) { - return writeOperation(p -> p.putIfAbsent(key, value)); - } - - @Override - public synchronized boolean remove(Object key, Object value) { - return writeOperation(p -> p.remove(key, value)); - } - - @Override - public synchronized boolean replace(Object key, Object oldValue, Object newValue) { - return writeOperation(p -> p.replace(key, oldValue, newValue)); - } - - @Override - public synchronized Object replace(Object key, Object value) { - return writeOperation(p -> p.replace(key, value)); - } - - @Override - public synchronized Object computeIfAbsent(Object key, Function mappingFunction) { - return writeOperation(p -> p.computeIfAbsent(key, mappingFunction)); - } - - @Override - public synchronized Object computeIfPresent( - Object key, BiFunction remappingFunction) { - return writeOperation(p -> p.computeIfPresent(key, remappingFunction)); - } - - @Override - public synchronized Object compute(Object key, BiFunction remappingFunction) { - return writeOperation(p -> p.compute(key, remappingFunction)); - } - - @Override - public synchronized Object merge( - Object key, Object value, BiFunction remappingFunction) { - return writeOperation(p -> p.merge(key, value, remappingFunction)); - } - - @Override - public synchronized void load(Reader reader) throws IOException { - try { - writeOperationVoid(p -> { - try { - p.load(reader); - } catch (IOException e) { - throw new IOError(e); - } - }); - } catch (IOError e) { - throw (IOException) e.getCause(); - } - } - - @Override - public synchronized void load(InputStream inStream) throws IOException { - try { - writeOperationVoid(p -> { - try { - p.load(inStream); - } catch (IOException e) { - throw new IOError(e); - } - }); - } catch (IOError e) { - throw (IOException) e.getCause(); - } - } - - @Override - public void save(OutputStream out, String comments) { - Properties props = new Properties(); - props.putAll(getter.get()); - props.save(out, comments); - } - - @Override - public void store(Writer writer, String comments) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.store(writer, comments); - } - - @Override - public void store(OutputStream out, String comments) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.store(out, comments); - } - - @Override - public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException { - throw new UnsupportedOperationException(); - } - - @Override - public void storeToXML(OutputStream os, String comment) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.storeToXML(os, comment); - } - - @Override - public void storeToXML(OutputStream os, String comment, String encoding) throws IOException { - Properties props = new Properties(); - props.putAll(getter.get()); - props.storeToXML(os, comment, encoding); - } -} diff --git a/api/maven-api-model/src/main/java/org/apache/maven/api/model/ImmutableCollections.java b/src/mdo/java/ImmutableCollections.java similarity index 99% rename from api/maven-api-model/src/main/java/org/apache/maven/api/model/ImmutableCollections.java rename to src/mdo/java/ImmutableCollections.java index 2da8c291d9..fe4faef8d9 100644 --- a/api/maven-api-model/src/main/java/org/apache/maven/api/model/ImmutableCollections.java +++ b/src/mdo/java/ImmutableCollections.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.api.model; +package ${package}; import java.io.Serializable; import java.util.AbstractList; diff --git a/maven-model/src/main/java/org/apache/maven/model/WrapperList.java b/src/mdo/java/WrapperList.java similarity index 99% rename from maven-model/src/main/java/org/apache/maven/model/WrapperList.java rename to src/mdo/java/WrapperList.java index 5bf6e65193..0799336aef 100644 --- a/maven-model/src/main/java/org/apache/maven/model/WrapperList.java +++ b/src/mdo/java/WrapperList.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.model; +package ${package}; import java.util.AbstractList; import java.util.ArrayList; diff --git a/maven-model/src/main/java/org/apache/maven/model/WrapperProperties.java b/src/mdo/java/WrapperProperties.java similarity index 99% rename from maven-model/src/main/java/org/apache/maven/model/WrapperProperties.java rename to src/mdo/java/WrapperProperties.java index bd10a91e93..46d7658365 100644 --- a/maven-model/src/main/java/org/apache/maven/model/WrapperProperties.java +++ b/src/mdo/java/WrapperProperties.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.model; +package ${package}; import java.io.IOError; import java.io.IOException; diff --git a/src/mdo/model-v3.vm b/src/mdo/model-v3.vm index 70326dec5e..5fd6ddc9e4 100644 --- a/src/mdo/model-v3.vm +++ b/src/mdo/model-v3.vm @@ -33,6 +33,10 @@ #set ( $dummy = $allFields.addAll( $cl.allFields ) ) #end #set ( $className = "${class.name}" ) +#MODELLO-VELOCITY#SAVE-OUTPUT-TO ${package.replace('.','/')}/WrapperList.java +#parse ( "java/WrapperList.java" ) +#MODELLO-VELOCITY#SAVE-OUTPUT-TO ${package.replace('.','/')}/WrapperProperties.java +#parse ( "java/WrapperProperties.java" ) #MODELLO-VELOCITY#SAVE-OUTPUT-TO ${package.replace('.','/')}/${className}.java #if ( $class.name != "InputLocation" && $class.name != "InputSource" ) #set ( $types = { } ) diff --git a/src/mdo/model.vm b/src/mdo/model.vm index c28fe29c41..d3f21a0e2c 100644 --- a/src/mdo/model.vm +++ b/src/mdo/model.vm @@ -31,6 +31,8 @@ #set ( $dummy = $allFields.addAll( $cl.getFields($version) ) ) #end #set ( $className = "${class.name}" ) +#MODELLO-VELOCITY#SAVE-OUTPUT-TO ${package.replace('.','/')}/ImmutableCollections.java +#parse ( "java/ImmutableCollections.java" ) #MODELLO-VELOCITY#SAVE-OUTPUT-TO ${package.replace('.','/')}/${className}.java #if ( $class.name != "InputLocation" && $class.name != "InputSource" ) #set ( $types = { } )