From: Martin Stockhammer Date: Fri, 24 Dec 2021 12:48:22 +0000 (+0100) Subject: Refactoring package names for maven proxy module X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea4413d1a06182ae2413379ed8aa3075ff58df4f;p=archiva.git Refactoring package names for maven proxy module --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java index 8b2d1f608..6fbfa9589 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/ArchivaIndexManagerMock.java @@ -28,9 +28,9 @@ import org.apache.archiva.indexer.IndexCreationFailedException; import org.apache.archiva.indexer.IndexUpdateFailedException; import org.apache.archiva.indexer.UnsupportedBaseContextException; import org.apache.archiva.proxy.ProxyRegistry; -import org.apache.archiva.maven.proxy.WagonFactory; -import org.apache.archiva.maven.proxy.WagonFactoryException; -import org.apache.archiva.maven.proxy.WagonFactoryRequest; +import org.apache.archiva.maven.common.proxy.WagonFactory; +import org.apache.archiva.maven.common.proxy.WagonFactoryException; +import org.apache.archiva.maven.common.proxy.WagonFactoryRequest; import org.apache.archiva.proxy.model.NetworkProxy; import org.apache.archiva.repository.EditableRepository; import org.apache.archiva.repository.ManagedRepository; diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/DebugTransferListener.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/DebugTransferListener.java new file mode 100644 index 000000000..cf885ea16 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/DebugTransferListener.java @@ -0,0 +1,74 @@ +package org.apache.archiva.maven.common.proxy; +/* + * 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 org.apache.maven.wagon.events.TransferEvent; +import org.apache.maven.wagon.events.TransferListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Olivier Lamy + * @since 1.4-M1 + */ +public class DebugTransferListener + implements TransferListener +{ + private Logger log = LoggerFactory.getLogger( getClass() ); + + @Override + public void transferInitiated( TransferEvent transferEvent ) + { + log.debug( "transferInitiated for resource {} on repository url {}", transferEvent.getResource().getName(), + transferEvent.getWagon().getRepository().getUrl() ); + } + + @Override + public void transferStarted( TransferEvent transferEvent ) + { + log.debug( "transferStarted for resource {} on repository url {}", transferEvent.getResource().getName(), + transferEvent.getWagon().getRepository().getUrl() ); + } + + @Override + public void transferProgress( TransferEvent transferEvent, byte[] bytes, int i ) + { + log.debug( "transferProgress for resource {} on repository url {}", transferEvent.getResource().getName(), + transferEvent.getWagon().getRepository().getUrl() ); + } + + @Override + public void transferCompleted( TransferEvent transferEvent ) + { + log.debug( "transferCompleted for resource {} on repository url {}", transferEvent.getResource().getName(), + transferEvent.getWagon().getRepository().getUrl() ); + } + + @Override + public void transferError( TransferEvent transferEvent ) + { + log.debug( "transferError for resource {} on repository url {}", transferEvent.getResource().getName(), + transferEvent.getWagon().getRepository().getUrl(), transferEvent.getException() ); + } + + @Override + public void debug( String s ) + { + log.debug( "wagon debug {}", s ); + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/DefaultWagonFactory.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/DefaultWagonFactory.java new file mode 100644 index 000000000..2e54de06d --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/DefaultWagonFactory.java @@ -0,0 +1,116 @@ +package org.apache.archiva.maven.common.proxy; + +/* + * 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 org.apache.commons.lang3.StringUtils; +import org.apache.maven.wagon.Wagon; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Properties; + +/** + * @author Olivier Lamy + * @since 1.4-M1 + */ +@Service ("wagonFactory") +public class DefaultWagonFactory + implements WagonFactory +{ + + private ApplicationContext applicationContext; + + private Logger logger = LoggerFactory.getLogger( getClass() ); + + private DebugTransferListener debugTransferListener = new DebugTransferListener(); + + @Inject + public DefaultWagonFactory( ApplicationContext applicationContext ) + { + this.applicationContext = applicationContext; + } + + @Override + public Wagon getWagon( WagonFactoryRequest wagonFactoryRequest ) + throws WagonFactoryException + { + try + { + String protocol = StringUtils.startsWith( wagonFactoryRequest.getProtocol(), "wagon#" ) + ? wagonFactoryRequest.getProtocol() + : "wagon#" + wagonFactoryRequest.getProtocol(); + + // if it's a ntlm proxy we have to lookup the wagon light which support thats + // wagon http client doesn't support that + if ( wagonFactoryRequest.getNetworkProxy() != null && wagonFactoryRequest.getNetworkProxy().isUseNtlm() ) + { + protocol = protocol + "-ntlm"; + } + + Wagon wagon = applicationContext.getBean( protocol, Wagon.class ); + wagon.addTransferListener( debugTransferListener ); + configureUserAgent( wagon, wagonFactoryRequest ); + return wagon; + } + catch ( BeansException e ) + { + throw new WagonFactoryException( e.getMessage(), e ); + } + } + + protected void configureUserAgent( Wagon wagon, WagonFactoryRequest wagonFactoryRequest ) + { + try + { + Class clazz = wagon.getClass(); + Method getHttpHeaders = clazz.getMethod( "getHttpHeaders" ); + + Properties headers = (Properties) getHttpHeaders.invoke( wagon ); + if ( headers == null ) + { + headers = new Properties(); + } + + headers.put( "User-Agent", wagonFactoryRequest.getUserAgent() ); + + if ( !wagonFactoryRequest.getHeaders().isEmpty() ) + { + for ( Map.Entry entry : wagonFactoryRequest.getHeaders().entrySet() ) + { + headers.put( entry.getKey(), entry.getValue() ); + } + } + + Method setHttpHeaders = clazz.getMethod( "setHttpHeaders", new Class[]{ Properties.class } ); + setHttpHeaders.invoke( wagon, headers ); + + logger.debug( "http headers set to: {}", headers ); + } + catch ( Exception e ) + { + logger.warn( "fail to configure User-Agent: {}", e.getMessage(), e ); + } + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactory.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactory.java new file mode 100644 index 000000000..4d0333fcf --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactory.java @@ -0,0 +1,37 @@ +package org.apache.archiva.maven.common.proxy; + +/* + * 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 org.apache.maven.wagon.Wagon; + +/** + * Create a Wagon instance for the given protocol. + */ +public interface WagonFactory +{ + /** + * Create a new Wagon instance for the given protocol. + * + * @param wagonFactoryRequest + * + * @return the Wagon instance + */ + Wagon getWagon( WagonFactoryRequest wagonFactoryRequest ) + throws WagonFactoryException; +} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactoryException.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactoryException.java new file mode 100755 index 000000000..2b7bdcb88 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactoryException.java @@ -0,0 +1,32 @@ +package org.apache.archiva.maven.common.proxy; + +/* + * 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. + */ + +/** + * @author Olivier Lamy + * @since 1.4-M1 + */ +public class WagonFactoryException + extends Exception +{ + public WagonFactoryException( String message, Throwable e ) + { + super( message, e ); + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactoryRequest.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactoryRequest.java new file mode 100644 index 000000000..d4d81fb5e --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/common/proxy/WagonFactoryRequest.java @@ -0,0 +1,178 @@ +package org.apache.archiva.maven.common.proxy; +/* + * 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 org.apache.archiva.proxy.model.NetworkProxy; +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Olivier Lamy + * @since 1.4-M4 + */ +public class WagonFactoryRequest +{ + + public static final String USER_AGENT_SYSTEM_PROPERTY = "archiva.userAgent"; + + private static String DEFAULT_USER_AGENT = "Java-Archiva"; + + /** + * the protocol to find the Wagon for, which must be prefixed with wagon#, for example + * wagon#http. to have a wagon supporting ntlm add -ntlm + */ + private String protocol; + + private Map headers = new HashMap<>(); + + private String userAgent = DEFAULT_USER_AGENT; + + static { + if ( StringUtils.isNotBlank( System.getProperty( USER_AGENT_SYSTEM_PROPERTY))) { + DEFAULT_USER_AGENT=System.getProperty(USER_AGENT_SYSTEM_PROPERTY); + } + } + + private NetworkProxy networkProxy; + + public WagonFactoryRequest() + { + // no op + } + + public WagonFactoryRequest( String protocol, Map headers ) + { + this.protocol = protocol; + this.headers = headers; + } + + public String getProtocol() + { + return protocol; + } + + public void setProtocol( String protocol ) + { + this.protocol = protocol; + } + + public WagonFactoryRequest protocol( String protocol ) + { + this.protocol = protocol; + return this; + } + + public Map getHeaders() + { + if ( this.headers == null ) + { + this.headers = new HashMap<>(); + } + return headers; + } + + public void setHeaders( Map headers ) + { + this.headers = headers; + } + + public WagonFactoryRequest headers( Map headers ) + { + this.headers = headers; + return this; + } + + public String getUserAgent() + { + return userAgent; + } + + public void setUserAgent( String userAgent ) + { + this.userAgent = userAgent; + } + + public WagonFactoryRequest userAgent( String userAgent ) + { + this.userAgent = userAgent; + return this; + } + + public NetworkProxy getNetworkProxy() + { + return networkProxy; + } + + public void setNetworkProxy( NetworkProxy networkProxy ) + { + this.networkProxy = networkProxy; + } + + public WagonFactoryRequest networkProxy( NetworkProxy networkProxy ) + { + this.networkProxy = networkProxy; + return this; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( !( o instanceof WagonFactoryRequest ) ) + { + return false; + } + + WagonFactoryRequest that = (WagonFactoryRequest) o; + + if ( protocol != null ? !protocol.equals( that.protocol ) : that.protocol != null ) + { + return false; + } + if ( userAgent != null ? !userAgent.equals( that.userAgent ) : that.userAgent != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = protocol != null ? protocol.hashCode() : 0; + result = 31 * result + ( userAgent != null ? userAgent.hashCode() : 0 ); + return result; + } + + @Override + public String toString() + { + return "WagonFactoryRequest{" + + "protocol='" + protocol + '\'' + + ", headers=" + headers + + ", userAgent='" + userAgent + '\'' + + ", networkProxy=" + networkProxy + + '}'; + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/DebugTransferListener.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/DebugTransferListener.java deleted file mode 100644 index 77a833fd1..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/DebugTransferListener.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.archiva.maven.proxy; -/* - * 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 org.apache.maven.wagon.events.TransferEvent; -import org.apache.maven.wagon.events.TransferListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Olivier Lamy - * @since 1.4-M1 - */ -public class DebugTransferListener - implements TransferListener -{ - private Logger log = LoggerFactory.getLogger( getClass() ); - - @Override - public void transferInitiated( TransferEvent transferEvent ) - { - log.debug( "transferInitiated for resource {} on repository url {}", transferEvent.getResource().getName(), - transferEvent.getWagon().getRepository().getUrl() ); - } - - @Override - public void transferStarted( TransferEvent transferEvent ) - { - log.debug( "transferStarted for resource {} on repository url {}", transferEvent.getResource().getName(), - transferEvent.getWagon().getRepository().getUrl() ); - } - - @Override - public void transferProgress( TransferEvent transferEvent, byte[] bytes, int i ) - { - log.debug( "transferProgress for resource {} on repository url {}", transferEvent.getResource().getName(), - transferEvent.getWagon().getRepository().getUrl() ); - } - - @Override - public void transferCompleted( TransferEvent transferEvent ) - { - log.debug( "transferCompleted for resource {} on repository url {}", transferEvent.getResource().getName(), - transferEvent.getWagon().getRepository().getUrl() ); - } - - @Override - public void transferError( TransferEvent transferEvent ) - { - log.debug( "transferError for resource {} on repository url {}", transferEvent.getResource().getName(), - transferEvent.getWagon().getRepository().getUrl(), transferEvent.getException() ); - } - - @Override - public void debug( String s ) - { - log.debug( "wagon debug {}", s ); - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/DefaultWagonFactory.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/DefaultWagonFactory.java deleted file mode 100644 index 6ce2d0bdc..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/DefaultWagonFactory.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.apache.archiva.maven.proxy; - -/* - * 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 org.apache.commons.lang3.StringUtils; -import org.apache.maven.wagon.Wagon; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Properties; - -/** - * @author Olivier Lamy - * @since 1.4-M1 - */ -@Service ("wagonFactory") -public class DefaultWagonFactory - implements WagonFactory -{ - - private ApplicationContext applicationContext; - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - private DebugTransferListener debugTransferListener = new DebugTransferListener(); - - @Inject - public DefaultWagonFactory( ApplicationContext applicationContext ) - { - this.applicationContext = applicationContext; - } - - @Override - public Wagon getWagon( WagonFactoryRequest wagonFactoryRequest ) - throws WagonFactoryException - { - try - { - String protocol = StringUtils.startsWith( wagonFactoryRequest.getProtocol(), "wagon#" ) - ? wagonFactoryRequest.getProtocol() - : "wagon#" + wagonFactoryRequest.getProtocol(); - - // if it's a ntlm proxy we have to lookup the wagon light which support thats - // wagon http client doesn't support that - if ( wagonFactoryRequest.getNetworkProxy() != null && wagonFactoryRequest.getNetworkProxy().isUseNtlm() ) - { - protocol = protocol + "-ntlm"; - } - - Wagon wagon = applicationContext.getBean( protocol, Wagon.class ); - wagon.addTransferListener( debugTransferListener ); - configureUserAgent( wagon, wagonFactoryRequest ); - return wagon; - } - catch ( BeansException e ) - { - throw new WagonFactoryException( e.getMessage(), e ); - } - } - - protected void configureUserAgent( Wagon wagon, WagonFactoryRequest wagonFactoryRequest ) - { - try - { - Class clazz = wagon.getClass(); - Method getHttpHeaders = clazz.getMethod( "getHttpHeaders" ); - - Properties headers = (Properties) getHttpHeaders.invoke( wagon ); - if ( headers == null ) - { - headers = new Properties(); - } - - headers.put( "User-Agent", wagonFactoryRequest.getUserAgent() ); - - if ( !wagonFactoryRequest.getHeaders().isEmpty() ) - { - for ( Map.Entry entry : wagonFactoryRequest.getHeaders().entrySet() ) - { - headers.put( entry.getKey(), entry.getValue() ); - } - } - - Method setHttpHeaders = clazz.getMethod( "setHttpHeaders", new Class[]{ Properties.class } ); - setHttpHeaders.invoke( wagon, headers ); - - logger.debug( "http headers set to: {}", headers ); - } - catch ( Exception e ) - { - logger.warn( "fail to configure User-Agent: {}", e.getMessage(), e ); - } - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactory.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactory.java deleted file mode 100644 index df05f1778..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apache.archiva.maven.proxy; - -/* - * 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 org.apache.maven.wagon.Wagon; - -/** - * Create a Wagon instance for the given protocol. - */ -public interface WagonFactory -{ - /** - * Create a new Wagon instance for the given protocol. - * - * @param wagonFactoryRequest - * - * @return the Wagon instance - */ - Wagon getWagon( WagonFactoryRequest wagonFactoryRequest ) - throws WagonFactoryException; -} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactoryException.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactoryException.java deleted file mode 100755 index 0e349d4ed..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactoryException.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.archiva.maven.proxy; - -/* - * 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. - */ - -/** - * @author Olivier Lamy - * @since 1.4-M1 - */ -public class WagonFactoryException - extends Exception -{ - public WagonFactoryException( String message, Throwable e ) - { - super( message, e ); - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactoryRequest.java b/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactoryRequest.java deleted file mode 100644 index 6980c5f8b..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-common/src/main/java/org/apache/archiva/maven/proxy/WagonFactoryRequest.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.apache.archiva.maven.proxy; -/* - * 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 org.apache.archiva.proxy.model.NetworkProxy; -import org.apache.commons.lang3.StringUtils; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Olivier Lamy - * @since 1.4-M4 - */ -public class WagonFactoryRequest -{ - - public static final String USER_AGENT_SYSTEM_PROPERTY = "archiva.userAgent"; - - private static String DEFAULT_USER_AGENT = "Java-Archiva"; - - /** - * the protocol to find the Wagon for, which must be prefixed with wagon#, for example - * wagon#http. to have a wagon supporting ntlm add -ntlm - */ - private String protocol; - - private Map headers = new HashMap<>(); - - private String userAgent = DEFAULT_USER_AGENT; - - static { - if ( StringUtils.isNotBlank( System.getProperty( USER_AGENT_SYSTEM_PROPERTY))) { - DEFAULT_USER_AGENT=System.getProperty(USER_AGENT_SYSTEM_PROPERTY); - } - } - - private NetworkProxy networkProxy; - - public WagonFactoryRequest() - { - // no op - } - - public WagonFactoryRequest( String protocol, Map headers ) - { - this.protocol = protocol; - this.headers = headers; - } - - public String getProtocol() - { - return protocol; - } - - public void setProtocol( String protocol ) - { - this.protocol = protocol; - } - - public WagonFactoryRequest protocol( String protocol ) - { - this.protocol = protocol; - return this; - } - - public Map getHeaders() - { - if ( this.headers == null ) - { - this.headers = new HashMap<>(); - } - return headers; - } - - public void setHeaders( Map headers ) - { - this.headers = headers; - } - - public WagonFactoryRequest headers( Map headers ) - { - this.headers = headers; - return this; - } - - public String getUserAgent() - { - return userAgent; - } - - public void setUserAgent( String userAgent ) - { - this.userAgent = userAgent; - } - - public WagonFactoryRequest userAgent( String userAgent ) - { - this.userAgent = userAgent; - return this; - } - - public NetworkProxy getNetworkProxy() - { - return networkProxy; - } - - public void setNetworkProxy( NetworkProxy networkProxy ) - { - this.networkProxy = networkProxy; - } - - public WagonFactoryRequest networkProxy( NetworkProxy networkProxy ) - { - this.networkProxy = networkProxy; - return this; - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( !( o instanceof WagonFactoryRequest ) ) - { - return false; - } - - WagonFactoryRequest that = (WagonFactoryRequest) o; - - if ( protocol != null ? !protocol.equals( that.protocol ) : that.protocol != null ) - { - return false; - } - if ( userAgent != null ? !userAgent.equals( that.userAgent ) : that.userAgent != null ) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - int result = protocol != null ? protocol.hashCode() : 0; - result = 31 * result + ( userAgent != null ? userAgent.hashCode() : 0 ); - return result; - } - - @Override - public String toString() - { - return "WagonFactoryRequest{" + - "protocol='" + protocol + '\'' + - ", headers=" + headers + - ", userAgent='" + userAgent + '\'' + - ", networkProxy=" + networkProxy + - '}'; - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-common/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-maven/archiva-maven-common/src/main/resources/META-INF/spring-context.xml index 2f61235d7..ff20c35dd 100644 --- a/archiva-modules/archiva-maven/archiva-maven-common/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-maven/archiva-maven-common/src/main/resources/META-INF/spring-context.xml @@ -28,6 +28,6 @@ default-lazy-init="true"> - + \ No newline at end of file diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/maven/indexer/MavenIndexManager.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/maven/indexer/MavenIndexManager.java index e45cfb8c1..512c74194 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/maven/indexer/MavenIndexManager.java +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/maven/indexer/MavenIndexManager.java @@ -27,9 +27,9 @@ import org.apache.archiva.indexer.IndexCreationFailedException; import org.apache.archiva.indexer.IndexUpdateFailedException; import org.apache.archiva.indexer.UnsupportedBaseContextException; import org.apache.archiva.proxy.ProxyRegistry; -import org.apache.archiva.maven.proxy.WagonFactory; -import org.apache.archiva.maven.proxy.WagonFactoryException; -import org.apache.archiva.maven.proxy.WagonFactoryRequest; +import org.apache.archiva.maven.common.proxy.WagonFactory; +import org.apache.archiva.maven.common.proxy.WagonFactoryException; +import org.apache.archiva.maven.common.proxy.WagonFactoryRequest; import org.apache.archiva.proxy.model.NetworkProxy; import org.apache.archiva.repository.EditableRepository; import org.apache.archiva.repository.ManagedRepository; diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/resources/spring-context.xml b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/resources/spring-context.xml index c734bbc98..0fc9f1d62 100644 --- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/resources/spring-context.xml +++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/test/resources/spring-context.xml @@ -28,7 +28,7 @@ default-lazy-init="false"> - + diff --git a/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven/model/Artifact.java b/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven/model/Artifact.java new file mode 100644 index 000000000..6f8b14019 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven/model/Artifact.java @@ -0,0 +1,658 @@ +package org.apache.archiva.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 javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; +import java.util.List; + +@XmlRootElement( name = "artifact" ) +public class Artifact + implements Serializable +{ + // The (optional) context for this result. + private String context; + + // Basic hit, direct to non-artifact resource. + private String url; + + // Advanced hit, reference to groupId. + private String groupId; + + // Advanced hit, reference to artifactId. + private String artifactId; + + private String repositoryId; + + private String version; + + /** + * Plugin goal prefix (only if packaging is "maven-plugin") + */ + private String prefix; + + /** + * Plugin goals (only if packaging is "maven-plugin") + */ + private List goals; + + /** + * contains osgi metadata Bundle-Version if available + * + * @since 1.4-M1 + */ + private String bundleVersion; + + /** + * contains osgi metadata Bundle-SymbolicName if available + * + * @since 1.4-M1 + */ + private String bundleSymbolicName; + + /** + * contains osgi metadata Export-Package if available + * + * @since 1.4-M1 + */ + private String bundleExportPackage; + + /** + * contains osgi metadata Export-Service if available + * + * @since 1.4-M1 + */ + private String bundleExportService; + + /** + * contains osgi metadata Bundle-Description if available + * + * @since 1.4-M1 + */ + private String bundleDescription; + + /** + * contains osgi metadata Bundle-Name if available + * + * @since 1.4-M1 + */ + private String bundleName; + + /** + * contains osgi metadata Bundle-License if available + * + * @since 1.4-M1 + */ + private String bundleLicense; + + /** + * contains osgi metadata Bundle-DocURL if available + * + * @since 1.4-M1 + */ + private String bundleDocUrl; + + /** + * contains osgi metadata Import-Package if available + * + * @since 1.4-M1 + */ + private String bundleImportPackage; + + /** + * contains osgi metadata Require-Bundle if available + * + * @since 1.4-M1 + */ + private String bundleRequireBundle; + + private String classifier; + + private String packaging; + + /** + * file extension of the artifact + * + * @since 1.4-M2 + */ + private String fileExtension; + + /** + * human readable size : not available for all services + * + * @since 1.4-M3 + */ + private String size; + + /** + * @since 1.4-M3 + */ + private String type; + + + /** + * @since 1.4-M3 + */ + private String path; + + /** + * concat of artifactId+'-'+version+'.'+type + * + * @since 1.4-M3 + */ + private String id; + + /** + * @since 1.4-M3 + */ + private String scope; + + + public Artifact() + { + // no op + } + + public Artifact( String groupId, String artifactId, String version ) + { + this.artifactId = artifactId; + this.groupId = groupId; + this.version = version; + } + + /** + * @since 1.4-M3 + */ + public Artifact( String groupId, String artifactId, String version, String scope ) + { + this( groupId, artifactId, version ); + this.scope = scope; + } + + /** + * @since 1.4-M3 + */ + public Artifact( String groupId, String artifactId, String version, String scope, String classifier ) + { + this( groupId, artifactId, version ); + this.scope = scope; + this.classifier = classifier; + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public String getRepositoryId() + { + return repositoryId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public void setRepositoryId( String repositoryId ) + { + this.repositoryId = repositoryId; + } + + public String getContext() + { + return context; + } + + public void setContext( String context ) + { + this.context = context; + } + + public String getUrl() + { + return url; + } + + public void setUrl( String url ) + { + this.url = url; + } + + public String getPrefix() + { + return prefix; + } + + public void setPrefix( String prefix ) + { + this.prefix = prefix; + } + + public List getGoals() + { + return goals; + } + + public void setGoals( List goals ) + { + this.goals = goals; + } + + public String getBundleVersion() + { + return bundleVersion; + } + + public void setBundleVersion( String bundleVersion ) + { + this.bundleVersion = bundleVersion; + } + + public String getBundleSymbolicName() + { + return bundleSymbolicName; + } + + public void setBundleSymbolicName( String bundleSymbolicName ) + { + this.bundleSymbolicName = bundleSymbolicName; + } + + public String getBundleExportPackage() + { + return bundleExportPackage; + } + + public void setBundleExportPackage( String bundleExportPackage ) + { + this.bundleExportPackage = bundleExportPackage; + } + + public String getBundleExportService() + { + return bundleExportService; + } + + public void setBundleExportService( String bundleExportService ) + { + this.bundleExportService = bundleExportService; + } + + public String getBundleDescription() + { + return bundleDescription; + } + + public void setBundleDescription( String bundleDescription ) + { + this.bundleDescription = bundleDescription; + } + + public String getBundleName() + { + return bundleName; + } + + public void setBundleName( String bundleName ) + { + this.bundleName = bundleName; + } + + public String getBundleLicense() + { + return bundleLicense; + } + + public void setBundleLicense( String bundleLicense ) + { + this.bundleLicense = bundleLicense; + } + + public String getBundleDocUrl() + { + return bundleDocUrl; + } + + public void setBundleDocUrl( String bundleDocUrl ) + { + this.bundleDocUrl = bundleDocUrl; + } + + public String getBundleImportPackage() + { + return bundleImportPackage; + } + + public void setBundleImportPackage( String bundleImportPackage ) + { + this.bundleImportPackage = bundleImportPackage; + } + + public String getBundleRequireBundle() + { + return bundleRequireBundle; + } + + public void setBundleRequireBundle( String bundleRequireBundle ) + { + this.bundleRequireBundle = bundleRequireBundle; + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + + public String getPackaging() + { + return packaging; + } + + public void setPackaging( String packaging ) + { + this.packaging = packaging; + } + + public String getFileExtension() + { + return fileExtension; + } + + public void setFileExtension( String fileExtension ) + { + this.fileExtension = fileExtension; + } + + public String getSize() + { + return size; + } + + public void setSize( String size ) + { + this.size = size; + } + + public String getType() + { + return type; + } + + public void setType( String type ) + { + this.type = type; + } + + public String getPath() + { + return path; + } + + public void setPath( String path ) + { + this.path = path; + } + + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } + + public String getScope() + { + return scope; + } + + public void setScope( String scope ) + { + this.scope = scope; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "Artifact" ); + sb.append( "{context='" ).append( context ).append( '\'' ); + sb.append( ", url='" ).append( url ).append( '\'' ); + sb.append( ", groupId='" ).append( groupId ).append( '\'' ); + sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); + sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); + sb.append( ", version='" ).append( version ).append( '\'' ); + sb.append( ", prefix='" ).append( prefix ).append( '\'' ); + sb.append( ", goals=" ).append( goals ); + sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); + sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); + sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); + sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); + sb.append( ", bundleDescription='" ).append( bundleDescription ).append( '\'' ); + sb.append( ", bundleName='" ).append( bundleName ).append( '\'' ); + sb.append( ", bundleLicense='" ).append( bundleLicense ).append( '\'' ); + sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' ); + sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); + sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); + sb.append( ", classifier='" ).append( classifier ).append( '\'' ); + sb.append( ", packaging='" ).append( packaging ).append( '\'' ); + sb.append( ", fileExtension='" ).append( fileExtension ).append( '\'' ); + sb.append( ", size='" ).append( size ).append( '\'' ); + sb.append( ", type='" ).append( type ).append( '\'' ); + sb.append( ", path='" ).append( path ).append( '\'' ); + sb.append( ", id='" ).append( id ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( !( o instanceof Artifact ) ) + { + return false; + } + + Artifact artifact = (Artifact) o; + + if ( !artifactId.equals( artifact.artifactId ) ) + { + return false; + } + if ( bundleDescription != null + ? !bundleDescription.equals( artifact.bundleDescription ) + : artifact.bundleDescription != null ) + { + return false; + } + if ( bundleDocUrl != null ? !bundleDocUrl.equals( artifact.bundleDocUrl ) : artifact.bundleDocUrl != null ) + { + return false; + } + if ( bundleExportPackage != null + ? !bundleExportPackage.equals( artifact.bundleExportPackage ) + : artifact.bundleExportPackage != null ) + { + return false; + } + if ( bundleExportService != null + ? !bundleExportService.equals( artifact.bundleExportService ) + : artifact.bundleExportService != null ) + { + return false; + } + if ( bundleImportPackage != null + ? !bundleImportPackage.equals( artifact.bundleImportPackage ) + : artifact.bundleImportPackage != null ) + { + return false; + } + if ( bundleLicense != null ? !bundleLicense.equals( artifact.bundleLicense ) : artifact.bundleLicense != null ) + { + return false; + } + if ( bundleName != null ? !bundleName.equals( artifact.bundleName ) : artifact.bundleName != null ) + { + return false; + } + if ( bundleRequireBundle != null + ? !bundleRequireBundle.equals( artifact.bundleRequireBundle ) + : artifact.bundleRequireBundle != null ) + { + return false; + } + if ( bundleSymbolicName != null + ? !bundleSymbolicName.equals( artifact.bundleSymbolicName ) + : artifact.bundleSymbolicName != null ) + { + return false; + } + if ( bundleVersion != null ? !bundleVersion.equals( artifact.bundleVersion ) : artifact.bundleVersion != null ) + { + return false; + } + if ( classifier != null ? !classifier.equals( artifact.classifier ) : artifact.classifier != null ) + { + return false; + } + if ( context != null ? !context.equals( artifact.context ) : artifact.context != null ) + { + return false; + } + if ( fileExtension != null ? !fileExtension.equals( artifact.fileExtension ) : artifact.fileExtension != null ) + { + return false; + } + if ( goals != null ? !goals.equals( artifact.goals ) : artifact.goals != null ) + { + return false; + } + if ( !groupId.equals( artifact.groupId ) ) + { + return false; + } + if ( id != null ? !id.equals( artifact.id ) : artifact.id != null ) + { + return false; + } + if ( packaging != null ? !packaging.equals( artifact.packaging ) : artifact.packaging != null ) + { + return false; + } + if ( path != null ? !path.equals( artifact.path ) : artifact.path != null ) + { + return false; + } + if ( prefix != null ? !prefix.equals( artifact.prefix ) : artifact.prefix != null ) + { + return false; + } + if ( repositoryId != null ? !repositoryId.equals( artifact.repositoryId ) : artifact.repositoryId != null ) + { + return false; + } + if ( scope != null ? !scope.equals( artifact.scope ) : artifact.scope != null ) + { + return false; + } + if ( size != null ? !size.equals( artifact.size ) : artifact.size != null ) + { + return false; + } + if ( type != null ? !type.equals( artifact.type ) : artifact.type != null ) + { + return false; + } + if ( url != null ? !url.equals( artifact.url ) : artifact.url != null ) + { + return false; + } + if ( !version.equals( artifact.version ) ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = context != null ? context.hashCode() : 0; + result = 31 * result + ( url != null ? url.hashCode() : 0 ); + result = 31 * result + groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); + result = 31 * result + ( repositoryId != null ? repositoryId.hashCode() : 0 ); + result = 31 * result + version.hashCode(); + result = 31 * result + ( prefix != null ? prefix.hashCode() : 0 ); + result = 31 * result + ( goals != null ? goals.hashCode() : 0 ); + result = 31 * result + ( bundleVersion != null ? bundleVersion.hashCode() : 0 ); + result = 31 * result + ( bundleSymbolicName != null ? bundleSymbolicName.hashCode() : 0 ); + result = 31 * result + ( bundleExportPackage != null ? bundleExportPackage.hashCode() : 0 ); + result = 31 * result + ( bundleExportService != null ? bundleExportService.hashCode() : 0 ); + result = 31 * result + ( bundleDescription != null ? bundleDescription.hashCode() : 0 ); + result = 31 * result + ( bundleName != null ? bundleName.hashCode() : 0 ); + result = 31 * result + ( bundleLicense != null ? bundleLicense.hashCode() : 0 ); + result = 31 * result + ( bundleDocUrl != null ? bundleDocUrl.hashCode() : 0 ); + result = 31 * result + ( bundleImportPackage != null ? bundleImportPackage.hashCode() : 0 ); + result = 31 * result + ( bundleRequireBundle != null ? bundleRequireBundle.hashCode() : 0 ); + result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); + result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 ); + result = 31 * result + ( fileExtension != null ? fileExtension.hashCode() : 0 ); + result = 31 * result + ( size != null ? size.hashCode() : 0 ); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + result = 31 * result + ( path != null ? path.hashCode() : 0 ); + result = 31 * result + ( id != null ? id.hashCode() : 0 ); + result = 31 * result + ( scope != null ? scope.hashCode() : 0 ); + return result; + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven/model/TreeEntry.java b/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven/model/TreeEntry.java new file mode 100644 index 000000000..e50e858ad --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven/model/TreeEntry.java @@ -0,0 +1,110 @@ +package org.apache.archiva.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 javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Olivier Lamy + */ +@XmlRootElement( name = "treeEntry" ) +public class TreeEntry + implements Serializable +{ + + private List childs = new ArrayList<>(); + + private Artifact artifact; + + private TreeEntry parent; + + public TreeEntry() + { + // no op + } + + public TreeEntry( Artifact artifact ) + { + this.artifact = artifact; + } + + + public Artifact getArtifact() + { + return artifact; + } + + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + public List getChilds() + { + return childs; + } + + public void setChilds( List childs ) + { + this.childs = childs; + } + + @XmlTransient + public TreeEntry getParent() + { + return parent; + } + + public void setParent( TreeEntry parent ) + { + this.parent = parent; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( !( o instanceof TreeEntry ) ) + { + return false; + } + + TreeEntry treeEntry = (TreeEntry) o; + + if ( artifact != null ? !artifact.equals( treeEntry.artifact ) : treeEntry.artifact != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + return artifact != null ? artifact.hashCode() : 0; + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven2/model/Artifact.java b/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven2/model/Artifact.java deleted file mode 100644 index cf010b309..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven2/model/Artifact.java +++ /dev/null @@ -1,659 +0,0 @@ -package org.apache.archiva.maven2.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 javax.xml.bind.annotation.XmlRootElement; -import java.io.Serializable; -import java.util.List; - -@XmlRootElement( name = "artifact" ) -public class Artifact - implements Serializable -{ - // The (optional) context for this result. - private String context; - - // Basic hit, direct to non-artifact resource. - private String url; - - // Advanced hit, reference to groupId. - private String groupId; - - // Advanced hit, reference to artifactId. - private String artifactId; - - private String repositoryId; - - private String version; - - /** - * Plugin goal prefix (only if packaging is "maven-plugin") - */ - private String prefix; - - /** - * Plugin goals (only if packaging is "maven-plugin") - */ - private List goals; - - /** - * contains osgi metadata Bundle-Version if available - * - * @since 1.4-M1 - */ - private String bundleVersion; - - /** - * contains osgi metadata Bundle-SymbolicName if available - * - * @since 1.4-M1 - */ - private String bundleSymbolicName; - - /** - * contains osgi metadata Export-Package if available - * - * @since 1.4-M1 - */ - private String bundleExportPackage; - - /** - * contains osgi metadata Export-Service if available - * - * @since 1.4-M1 - */ - private String bundleExportService; - - /** - * contains osgi metadata Bundle-Description if available - * - * @since 1.4-M1 - */ - private String bundleDescription; - - /** - * contains osgi metadata Bundle-Name if available - * - * @since 1.4-M1 - */ - private String bundleName; - - /** - * contains osgi metadata Bundle-License if available - * - * @since 1.4-M1 - */ - private String bundleLicense; - - /** - * contains osgi metadata Bundle-DocURL if available - * - * @since 1.4-M1 - */ - private String bundleDocUrl; - - /** - * contains osgi metadata Import-Package if available - * - * @since 1.4-M1 - */ - private String bundleImportPackage; - - /** - * contains osgi metadata Require-Bundle if available - * - * @since 1.4-M1 - */ - private String bundleRequireBundle; - - private String classifier; - - private String packaging; - - /** - * file extension of the artifact - * - * @since 1.4-M2 - */ - private String fileExtension; - - /** - * human readable size : not available for all services - * - * @since 1.4-M3 - */ - private String size; - - /** - * @since 1.4-M3 - */ - private String type; - - - /** - * @since 1.4-M3 - */ - private String path; - - /** - * concat of artifactId+'-'+version+'.'+type - * - * @since 1.4-M3 - */ - private String id; - - /** - * @since 1.4-M3 - */ - private String scope; - - - public Artifact() - { - // no op - } - - public Artifact( String groupId, String artifactId, String version ) - { - this.artifactId = artifactId; - this.groupId = groupId; - this.version = version; - } - - /** - * @since 1.4-M3 - */ - public Artifact( String groupId, String artifactId, String version, String scope ) - { - this( groupId, artifactId, version ); - this.scope = scope; - } - - /** - * @since 1.4-M3 - */ - public Artifact( String groupId, String artifactId, String version, String scope, String classifier ) - { - this( groupId, artifactId, version ); - this.scope = scope; - this.classifier = classifier; - } - - public String getGroupId() - { - return groupId; - } - - public String getArtifactId() - { - return artifactId; - } - - public String getVersion() - { - return version; - } - - public String getRepositoryId() - { - return repositoryId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public void setVersion( String version ) - { - this.version = version; - } - - public void setRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - } - - public String getContext() - { - return context; - } - - public void setContext( String context ) - { - this.context = context; - } - - public String getUrl() - { - return url; - } - - public void setUrl( String url ) - { - this.url = url; - } - - public String getPrefix() - { - return prefix; - } - - public void setPrefix( String prefix ) - { - this.prefix = prefix; - } - - public List getGoals() - { - return goals; - } - - public void setGoals( List goals ) - { - this.goals = goals; - } - - public String getBundleVersion() - { - return bundleVersion; - } - - public void setBundleVersion( String bundleVersion ) - { - this.bundleVersion = bundleVersion; - } - - public String getBundleSymbolicName() - { - return bundleSymbolicName; - } - - public void setBundleSymbolicName( String bundleSymbolicName ) - { - this.bundleSymbolicName = bundleSymbolicName; - } - - public String getBundleExportPackage() - { - return bundleExportPackage; - } - - public void setBundleExportPackage( String bundleExportPackage ) - { - this.bundleExportPackage = bundleExportPackage; - } - - public String getBundleExportService() - { - return bundleExportService; - } - - public void setBundleExportService( String bundleExportService ) - { - this.bundleExportService = bundleExportService; - } - - public String getBundleDescription() - { - return bundleDescription; - } - - public void setBundleDescription( String bundleDescription ) - { - this.bundleDescription = bundleDescription; - } - - public String getBundleName() - { - return bundleName; - } - - public void setBundleName( String bundleName ) - { - this.bundleName = bundleName; - } - - public String getBundleLicense() - { - return bundleLicense; - } - - public void setBundleLicense( String bundleLicense ) - { - this.bundleLicense = bundleLicense; - } - - public String getBundleDocUrl() - { - return bundleDocUrl; - } - - public void setBundleDocUrl( String bundleDocUrl ) - { - this.bundleDocUrl = bundleDocUrl; - } - - public String getBundleImportPackage() - { - return bundleImportPackage; - } - - public void setBundleImportPackage( String bundleImportPackage ) - { - this.bundleImportPackage = bundleImportPackage; - } - - public String getBundleRequireBundle() - { - return bundleRequireBundle; - } - - public void setBundleRequireBundle( String bundleRequireBundle ) - { - this.bundleRequireBundle = bundleRequireBundle; - } - - public String getClassifier() - { - return classifier; - } - - public void setClassifier( String classifier ) - { - this.classifier = classifier; - } - - - public String getPackaging() - { - return packaging; - } - - public void setPackaging( String packaging ) - { - this.packaging = packaging; - } - - public String getFileExtension() - { - return fileExtension; - } - - public void setFileExtension( String fileExtension ) - { - this.fileExtension = fileExtension; - } - - public String getSize() - { - return size; - } - - public void setSize( String size ) - { - this.size = size; - } - - public String getType() - { - return type; - } - - public void setType( String type ) - { - this.type = type; - } - - public String getPath() - { - return path; - } - - public void setPath( String path ) - { - this.path = path; - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getScope() - { - return scope; - } - - public void setScope( String scope ) - { - this.scope = scope; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder(); - sb.append( "Artifact" ); - sb.append( "{context='" ).append( context ).append( '\'' ); - sb.append( ", url='" ).append( url ).append( '\'' ); - sb.append( ", groupId='" ).append( groupId ).append( '\'' ); - sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); - sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' ); - sb.append( ", version='" ).append( version ).append( '\'' ); - sb.append( ", prefix='" ).append( prefix ).append( '\'' ); - sb.append( ", goals=" ).append( goals ); - sb.append( ", bundleVersion='" ).append( bundleVersion ).append( '\'' ); - sb.append( ", bundleSymbolicName='" ).append( bundleSymbolicName ).append( '\'' ); - sb.append( ", bundleExportPackage='" ).append( bundleExportPackage ).append( '\'' ); - sb.append( ", bundleExportService='" ).append( bundleExportService ).append( '\'' ); - sb.append( ", bundleDescription='" ).append( bundleDescription ).append( '\'' ); - sb.append( ", bundleName='" ).append( bundleName ).append( '\'' ); - sb.append( ", bundleLicense='" ).append( bundleLicense ).append( '\'' ); - sb.append( ", bundleDocUrl='" ).append( bundleDocUrl ).append( '\'' ); - sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' ); - sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' ); - sb.append( ", classifier='" ).append( classifier ).append( '\'' ); - sb.append( ", packaging='" ).append( packaging ).append( '\'' ); - sb.append( ", fileExtension='" ).append( fileExtension ).append( '\'' ); - sb.append( ", size='" ).append( size ).append( '\'' ); - sb.append( ", type='" ).append( type ).append( '\'' ); - sb.append( ", path='" ).append( path ).append( '\'' ); - sb.append( ", id='" ).append( id ).append( '\'' ); - sb.append( '}' ); - return sb.toString(); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( !( o instanceof Artifact ) ) - { - return false; - } - - Artifact artifact = (Artifact) o; - - if ( !artifactId.equals( artifact.artifactId ) ) - { - return false; - } - if ( bundleDescription != null - ? !bundleDescription.equals( artifact.bundleDescription ) - : artifact.bundleDescription != null ) - { - return false; - } - if ( bundleDocUrl != null ? !bundleDocUrl.equals( artifact.bundleDocUrl ) : artifact.bundleDocUrl != null ) - { - return false; - } - if ( bundleExportPackage != null - ? !bundleExportPackage.equals( artifact.bundleExportPackage ) - : artifact.bundleExportPackage != null ) - { - return false; - } - if ( bundleExportService != null - ? !bundleExportService.equals( artifact.bundleExportService ) - : artifact.bundleExportService != null ) - { - return false; - } - if ( bundleImportPackage != null - ? !bundleImportPackage.equals( artifact.bundleImportPackage ) - : artifact.bundleImportPackage != null ) - { - return false; - } - if ( bundleLicense != null ? !bundleLicense.equals( artifact.bundleLicense ) : artifact.bundleLicense != null ) - { - return false; - } - if ( bundleName != null ? !bundleName.equals( artifact.bundleName ) : artifact.bundleName != null ) - { - return false; - } - if ( bundleRequireBundle != null - ? !bundleRequireBundle.equals( artifact.bundleRequireBundle ) - : artifact.bundleRequireBundle != null ) - { - return false; - } - if ( bundleSymbolicName != null - ? !bundleSymbolicName.equals( artifact.bundleSymbolicName ) - : artifact.bundleSymbolicName != null ) - { - return false; - } - if ( bundleVersion != null ? !bundleVersion.equals( artifact.bundleVersion ) : artifact.bundleVersion != null ) - { - return false; - } - if ( classifier != null ? !classifier.equals( artifact.classifier ) : artifact.classifier != null ) - { - return false; - } - if ( context != null ? !context.equals( artifact.context ) : artifact.context != null ) - { - return false; - } - if ( fileExtension != null ? !fileExtension.equals( artifact.fileExtension ) : artifact.fileExtension != null ) - { - return false; - } - if ( goals != null ? !goals.equals( artifact.goals ) : artifact.goals != null ) - { - return false; - } - if ( !groupId.equals( artifact.groupId ) ) - { - return false; - } - if ( id != null ? !id.equals( artifact.id ) : artifact.id != null ) - { - return false; - } - if ( packaging != null ? !packaging.equals( artifact.packaging ) : artifact.packaging != null ) - { - return false; - } - if ( path != null ? !path.equals( artifact.path ) : artifact.path != null ) - { - return false; - } - if ( prefix != null ? !prefix.equals( artifact.prefix ) : artifact.prefix != null ) - { - return false; - } - if ( repositoryId != null ? !repositoryId.equals( artifact.repositoryId ) : artifact.repositoryId != null ) - { - return false; - } - if ( scope != null ? !scope.equals( artifact.scope ) : artifact.scope != null ) - { - return false; - } - if ( size != null ? !size.equals( artifact.size ) : artifact.size != null ) - { - return false; - } - if ( type != null ? !type.equals( artifact.type ) : artifact.type != null ) - { - return false; - } - if ( url != null ? !url.equals( artifact.url ) : artifact.url != null ) - { - return false; - } - if ( !version.equals( artifact.version ) ) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - int result = context != null ? context.hashCode() : 0; - result = 31 * result + ( url != null ? url.hashCode() : 0 ); - result = 31 * result + groupId.hashCode(); - result = 31 * result + artifactId.hashCode(); - result = 31 * result + ( repositoryId != null ? repositoryId.hashCode() : 0 ); - result = 31 * result + version.hashCode(); - result = 31 * result + ( prefix != null ? prefix.hashCode() : 0 ); - result = 31 * result + ( goals != null ? goals.hashCode() : 0 ); - result = 31 * result + ( bundleVersion != null ? bundleVersion.hashCode() : 0 ); - result = 31 * result + ( bundleSymbolicName != null ? bundleSymbolicName.hashCode() : 0 ); - result = 31 * result + ( bundleExportPackage != null ? bundleExportPackage.hashCode() : 0 ); - result = 31 * result + ( bundleExportService != null ? bundleExportService.hashCode() : 0 ); - result = 31 * result + ( bundleDescription != null ? bundleDescription.hashCode() : 0 ); - result = 31 * result + ( bundleName != null ? bundleName.hashCode() : 0 ); - result = 31 * result + ( bundleLicense != null ? bundleLicense.hashCode() : 0 ); - result = 31 * result + ( bundleDocUrl != null ? bundleDocUrl.hashCode() : 0 ); - result = 31 * result + ( bundleImportPackage != null ? bundleImportPackage.hashCode() : 0 ); - result = 31 * result + ( bundleRequireBundle != null ? bundleRequireBundle.hashCode() : 0 ); - result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); - result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 ); - result = 31 * result + ( fileExtension != null ? fileExtension.hashCode() : 0 ); - result = 31 * result + ( size != null ? size.hashCode() : 0 ); - result = 31 * result + ( type != null ? type.hashCode() : 0 ); - result = 31 * result + ( path != null ? path.hashCode() : 0 ); - result = 31 * result + ( id != null ? id.hashCode() : 0 ); - result = 31 * result + ( scope != null ? scope.hashCode() : 0 ); - return result; - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven2/model/TreeEntry.java b/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven2/model/TreeEntry.java deleted file mode 100644 index 23a3acf5c..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-model/src/main/java/org/apache/archiva/maven2/model/TreeEntry.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.apache.archiva.maven2.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 javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Olivier Lamy - */ -@XmlRootElement( name = "treeEntry" ) -public class TreeEntry - implements Serializable -{ - - private List childs = new ArrayList<>(); - - private Artifact artifact; - - private TreeEntry parent; - - public TreeEntry() - { - // no op - } - - public TreeEntry( Artifact artifact ) - { - this.artifact = artifact; - } - - - public Artifact getArtifact() - { - return artifact; - } - - public void setArtifact( Artifact artifact ) - { - this.artifact = artifact; - } - - public List getChilds() - { - return childs; - } - - public void setChilds( List childs ) - { - this.childs = childs; - } - - @XmlTransient - public TreeEntry getParent() - { - return parent; - } - - public void setParent( TreeEntry parent ) - { - this.parent = parent; - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( !( o instanceof TreeEntry ) ) - { - return false; - } - - TreeEntry treeEntry = (TreeEntry) o; - - if ( artifact != null ? !artifact.equals( treeEntry.artifact ) : treeEntry.artifact != null ) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - return artifact != null ? artifact.hashCode() : 0; - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-model/src/test/java/org/apache/archiva/maven/model/ModelTest.java b/archiva-modules/archiva-maven/archiva-maven-model/src/test/java/org/apache/archiva/maven/model/ModelTest.java new file mode 100644 index 000000000..9600d2b90 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-model/src/test/java/org/apache/archiva/maven/model/ModelTest.java @@ -0,0 +1,71 @@ +package org.apache.archiva.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 com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import org.json.JSONObject; +import org.junit.jupiter.api.Test; + +import javax.xml.bind.JAXBException; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + + +public class ModelTest +{ + @Test + void testTreeEntry() throws JAXBException, IOException + { + TreeEntry parent = new TreeEntry( ); + TreeEntry entry = new TreeEntry( ); + entry.setParent( parent ); + Artifact artifact1 = new Artifact( ); + artifact1.setGroupId( "test.group" ); + artifact1.setArtifactId( "artifact1" ); + artifact1.setVersion( "1.0" ); + entry.setArtifact( artifact1 ); + + TreeEntry child1 = new TreeEntry( ); + TreeEntry child2 = new TreeEntry( ); + child1.setParent( entry ); + child2.setParent( entry ); + Artifact artifact2 = new Artifact( ); + artifact2.setGroupId( "test.group" ); + artifact2.setArtifactId( "artifact1" ); + artifact2.setVersion( "1.1" ); + child1.setArtifact( artifact2 ); + child2.setArtifact( artifact2 ); + entry.setChilds( Arrays.asList( child1, child2) ); + + ObjectMapper objectMapper = new ObjectMapper( ); + objectMapper.registerModule( new JaxbAnnotationModule( ) ); + StringWriter sw = new StringWriter( ); + objectMapper.writeValue( sw, entry ); + + JSONObject js = new JSONObject( sw.toString() ); + assertFalse( js.has( "parent" ) ); + assertTrue( js.has( "childs" ) ); + assertEquals(2, js.getJSONArray( "childs" ).length()); + assertTrue( js.has( "artifact" ) ); + + } +} diff --git a/archiva-modules/archiva-maven/archiva-maven-model/src/test/java/org/apache/archiva/maven2/model/ModelTest.java b/archiva-modules/archiva-maven/archiva-maven-model/src/test/java/org/apache/archiva/maven2/model/ModelTest.java deleted file mode 100644 index 75c4cc273..000000000 --- a/archiva-modules/archiva-maven/archiva-maven-model/src/test/java/org/apache/archiva/maven2/model/ModelTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.apache.archiva.maven2.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 com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; -import org.json.JSONObject; -import org.junit.jupiter.api.Test; - -import javax.xml.bind.JAXBException; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Arrays; - -import static org.junit.jupiter.api.Assertions.*; - - -public class ModelTest -{ - @Test - void testTreeEntry() throws JAXBException, IOException - { - TreeEntry parent = new TreeEntry( ); - TreeEntry entry = new TreeEntry( ); - entry.setParent( parent ); - Artifact artifact1 = new Artifact( ); - artifact1.setGroupId( "test.group" ); - artifact1.setArtifactId( "artifact1" ); - artifact1.setVersion( "1.0" ); - entry.setArtifact( artifact1 ); - - TreeEntry child1 = new TreeEntry( ); - TreeEntry child2 = new TreeEntry( ); - child1.setParent( entry ); - child2.setParent( entry ); - Artifact artifact2 = new Artifact( ); - artifact2.setGroupId( "test.group" ); - artifact2.setArtifactId( "artifact1" ); - artifact2.setVersion( "1.1" ); - child1.setArtifact( artifact2 ); - child2.setArtifact( artifact2 ); - entry.setChilds( Arrays.asList( child1, child2) ); - - ObjectMapper objectMapper = new ObjectMapper( ); - objectMapper.registerModule( new JaxbAnnotationModule( ) ); - StringWriter sw = new StringWriter( ); - objectMapper.writeValue( sw, entry ); - - JSONObject js = new JSONObject( sw.toString() ); - assertFalse( js.has( "parent" ) ); - assertTrue( js.has( "childs" ) ); - assertEquals(2, js.getJSONArray( "childs" ).length()); - assertTrue( js.has( "artifact" ) ); - - } -} diff --git a/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml b/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml index afd9022c6..c7f26a14e 100644 --- a/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml +++ b/archiva-modules/archiva-maven/archiva-maven-proxy/pom.xml @@ -234,6 +234,23 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.build.directory}/appserver-base + ${project.build.directory}/appserver-base + ${project.build.directory}/appserver-base + ${redbackTestJdbcUrl} + ${redbackTestJdbcDriver} + mock + ${openjpa.Log} + + + +