001/**
002 * Copyright (C) 2006-2024 Talend Inc. - www.talend.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.talend.sdk.component.runtime.manager.service;
017
018import java.nio.file.Path;
019import java.util.regex.Pattern;
020
021/**
022 * m2 discovery process is used for plugins/connectors loading.
023 */
024public interface MavenRepositoryResolver {
025    // a set of system properties available in the framework
026
027    /**
028     * System property used to enforce maven repository location.
029     */
030    String TALEND_COMPONENT_MANAGER_M2_REPOSITORY = "talend.component.manager.m2.repository";
031
032    /**
033     * System property used to enforce the location of settings.xml.
034     */
035    String TALEND_COMPONENT_MANAGER_M2_SETTINGS = "talend.component.manager.m2.settings";
036
037    /**
038     * Studio's property used to specify maven repository location. If set {@code global}, the Studio uses user's
039     * settings. Otherwise, Studio's internal repository is used.
040     */
041    String STUDIO_MVN_REPOSITORY = "maven.repository";
042
043    // a set of environment variables available in the framework or in maven builtin...
044
045    String M2_HOME = "M2_HOME";
046
047    String MAVEN_HOME = "MAVEN_HOME";
048
049    // a set of constants
050
051    String M2_REPOSITORY = ".m2/repository";
052
053    String M2_SETTINGS = ".m2/settings.xml";
054
055    String CONF_SETTINGS = "conf/settings.xml";
056
057    String USER_HOME = System.getProperty("user.home", "");
058
059    // some settings.xml regexp patterns
060    Pattern XML_COMMENTS_PATTERN = Pattern.compile("(<!--.*?-->)", Pattern.DOTALL);
061
062    Pattern XML_EMPTY_LINES_PATTERN = Pattern.compile("^\\s*$|\\n|\\r\\n");
063
064    Pattern XML_LOCAL_REPO_PATTERN =
065            Pattern.compile(".*<localRepository>(.+)</localRepository>.*", Pattern.CASE_INSENSITIVE);
066
067    /**
068     * Main entry point for the discovery process.
069     * It allows to priorize how we may find the local maven repository path according the context.
070     *
071     * @return local maven repository path discovered.
072     */
073    Path discover();
074
075    /**
076     * Make sure that we provide a fallback if discovery fails.
077     * such like {@code return PathHandler.get(USER_HOME).resolve(M2_REPOSITORY);}
078     *
079     * @return a fallback path to local maven repository
080     */
081    Path fallback();
082
083}