@Override
  public void upgrade(UpgradeMessage message) throws ConfigurationIsCorruptedException {
    org.sonatype.nexus.configuration.model.v1_4_1.Configuration oldc =
        (org.sonatype.nexus.configuration.model.v1_4_1.Configuration) message.getConfiguration();

    org.sonatype.nexus.configuration.model.v1_4_2.Configuration newc =
        new BasicVersionConverter().convertConfiguration(oldc);

    // fix for NEXUS-3604
    for (org.sonatype.nexus.configuration.model.v1_4_2.CRepository repository :
        newc.getRepositories()) {
      if ("org.sonatype.nexus.proxy.repository.GroupRepository"
          .equals(repository.getProviderRole())) {
        repository.setSearchable(false);
      }
    }

    newc.setVersion(org.sonatype.nexus.configuration.model.v1_4_2.Configuration.MODEL_VERSION);
    message.setModelVersion(
        org.sonatype.nexus.configuration.model.v1_4_2.Configuration.MODEL_VERSION);
    message.setConfiguration(newc);
  }
Exemple #2
0
  public void upgrade(UpgradeMessage message) throws ConfigurationIsCorruptedException {
    Configuration oldc = (Configuration) message.getConfiguration();
    org.sonatype.nexus.configuration.model.v1_0_2.Configuration newc =
        new org.sonatype.nexus.configuration.model.v1_0_2.Configuration();

    newc.setVersion(org.sonatype.nexus.configuration.model.v1_0_2.Configuration.MODEL_VERSION);
    newc.setWorkingDirectory(oldc.getWorkingDirectory());
    newc.setApplicationLogDirectory(oldc.getApplicationLogDirectory());

    CSecurity security = new CSecurity();
    security.setEnabled(oldc.getSecurity().isEnabled());
    security.setAnonymousAccessEnabled(oldc.getSecurity().isAnonymousAccessEnabled());
    if (oldc.getSecurity().getAuthenticationSource() != null) {
      CAuthSource authenticationSource = new CAuthSource();
      authenticationSource.setType(oldc.getSecurity().getAuthenticationSource().getType());
      if (oldc.getSecurity().getAuthenticationSource().getProperties() != null) {
        authenticationSource.setProperties(
            copyCProps1_0_1(oldc.getSecurity().getAuthenticationSource().getProperties()));
      }
      security.setAuthenticationSource(authenticationSource);
    }
    if (oldc.getSecurity().getRealms() != null) {
      List<CAuthzSource> realms =
          new ArrayList<CAuthzSource>(oldc.getSecurity().getRealms().size());
      for (org.sonatype.nexus.configuration.model.v1_0_1.CAuthzSource oldrealm :
          (List<org.sonatype.nexus.configuration.model.v1_0_1.CAuthzSource>)
              oldc.getSecurity().getRealms()) {
        CAuthzSource newrealm = new CAuthzSource();
        newrealm.setId(oldrealm.getId());
        newrealm.setType(oldrealm.getType());
        newrealm.setProperties(copyCProps1_0_1(oldrealm.getProperties()));
        realms.add(newrealm);
      }
      security.setRealms(realms);
    }
    newc.setSecurity(security);

    if (oldc.getGlobalConnectionSettings() != null) {
      newc.setGlobalConnectionSettings(
          copyCRemoteConnectionSettings1_0_1(oldc.getGlobalConnectionSettings()));
    } else {
      newc.setGlobalConnectionSettings(new CRemoteConnectionSettings());
    }

    if (oldc.getGlobalHttpProxySettings() != null) {
      newc.setGlobalHttpProxySettings(
          copyCRemoteHttpProxySettings1_0_1(oldc.getGlobalHttpProxySettings()));
    }

    if (oldc.getRouting() != null) {
      CRouting routing = new CRouting();
      routing.setFollowLinks(oldc.getRouting().isFollowLinks());
      routing.setNotFoundCacheTTL(oldc.getRouting().getNotFoundCacheTTL());
      if (oldc.getRouting().getGroups() != null) {
        CGroupsSetting groups = new CGroupsSetting();
        groups.setStopItemSearchOnFirstFoundFile(
            oldc.getRouting().getGroups().isStopItemSearchOnFirstFoundFile());
        groups.setMergeMetadata(oldc.getRouting().getGroups().isMergeMetadata());
        routing.setGroups(groups);
      }
      newc.setRouting(routing);
    } else {
      newc.setRouting(new CRouting());
      newc.getRouting().setGroups(new CGroupsSetting());
    }

    newc.setRestApi(new CRestApiSettings());

    newc.setHttpProxy(new CHttpProxySettings());

    List<CRepository> repositories = new ArrayList<CRepository>(oldc.getRepositories().size());
    for (org.sonatype.nexus.configuration.model.v1_0_1.CRepository oldrepos :
        (List<org.sonatype.nexus.configuration.model.v1_0_1.CRepository>) oldc.getRepositories()) {
      CRepository newrepos = copyCRepository1_0_1(oldrepos);
      newrepos.setRepositoryPolicy(oldrepos.getRepositoryPolicy());
      repositories.add(newrepos);
    }
    newc.setRepositories(repositories);

    if (oldc.getRepositoryShadows() != null) {
      List<CRepositoryShadow> repositoryShadows =
          new ArrayList<CRepositoryShadow>(oldc.getRepositoryShadows().size());
      for (org.sonatype.nexus.configuration.model.v1_0_1.CRepositoryShadow oldshadow :
          (List<org.sonatype.nexus.configuration.model.v1_0_1.CRepositoryShadow>)
              oldc.getRepositoryShadows()) {
        CRepositoryShadow newshadow = new CRepositoryShadow();
        newshadow.setId(oldshadow.getId());
        newshadow.setName(oldshadow.getName());
        newshadow.setLocalStatus(
            oldshadow.isAvailable()
                ? org.sonatype.nexus.configuration.model.v1_0_2.Configuration
                    .LOCAL_STATUS_IN_SERVICE
                : org.sonatype.nexus.configuration.model.v1_0_2.Configuration
                    .LOCAL_STATUS_OUT_OF_SERVICE);
        newshadow.setShadowOf(oldshadow.getShadowOf());
        newshadow.setType(oldshadow.getType());
        newshadow.setSyncAtStartup(oldshadow.isSyncAtStartup());
        newshadow.setRealmId(oldshadow.getRealmId());
        repositoryShadows.add(newshadow);
      }
      newc.setRepositoryShadows(repositoryShadows);
    }

    if (oldc.getRepositoryGrouping() != null) {
      CRepositoryGrouping repositoryGrouping = new CRepositoryGrouping();
      if (oldc.getRepositoryGrouping().getPathMappings() != null) {
        for (CGroupsSettingPathMappingItem oldItem :
            (List<CGroupsSettingPathMappingItem>) oldc.getRepositoryGrouping().getPathMappings()) {
          org.sonatype.nexus.configuration.model.v1_0_2.CGroupsSettingPathMappingItem newItem =
              new org.sonatype.nexus.configuration.model.v1_0_2.CGroupsSettingPathMappingItem();

          newItem.setId(oldItem.getId());

          newItem.setRoutePattern(oldItem.getRoutePattern());

          newItem.setRouteType(oldItem.getRouteType());

          newItem.setRepositories(oldItem.getRepositories());

          repositoryGrouping.addPathMapping(newItem);
        }
      }
      List<CRepositoryGroup> repositoryGroups =
          new ArrayList<CRepositoryGroup>(
              oldc.getRepositoryGrouping().getRepositoryGroups().size());
      for (org.sonatype.nexus.configuration.model.v1_0_1.CRepositoryGroup oldgroup :
          (List<org.sonatype.nexus.configuration.model.v1_0_1.CRepositoryGroup>)
              oldc.getRepositoryGrouping().getRepositoryGroups()) {
        CRepositoryGroup newgroup = new CRepositoryGroup();
        newgroup.setGroupId(oldgroup.getGroupId());
        // both are List<String>
        newgroup.setRepositories(oldgroup.getRepositories());
        repositoryGroups.add(newgroup);
      }
      repositoryGrouping.setRepositoryGroups(repositoryGroups);
      newc.setRepositoryGrouping(repositoryGrouping);
    }

    message.setModelVersion(
        org.sonatype.nexus.configuration.model.v1_0_2.Configuration.MODEL_VERSION);
    message.setConfiguration(newc);
  }